Skip to content
Snippets Groups Projects
Commit 14be4ca0 authored by Rico's avatar Rico
Browse files

add smooth follow scripts

parent ff29fceb
No related branches found
No related tags found
No related merge requests found
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class SmoothFollow : MonoBehaviour
{
public Transform target;
public float smoothTime = 1;
private Vector3 currentVelocity = Vector3.zero;
private Vector3 currentVelocityAngles = Vector3.zero;
// Start is called before the first frame update
void Start()
{
}
// Update is called once per frame
void Update()
{
this.transform.position = Vector3.SmoothDamp(this.transform.position, target.transform.position, ref currentVelocity, smoothTime);
//this.transform.localEulerAngles = Vector3.SmoothDamp(this.transform.localEulerAngles, target.transform.eulerAngles, ref currentVelocityAngles, smoothTime);
this.transform.localEulerAngles = target.eulerAngles;
}
}
fileFormatVersion: 2
guid: 45558166aefd1c544bc4b1678521e0c7
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
using System.Collections;
using System.Linq;
using System.Collections.Generic;
using UnityEngine;
public class SmoothFollowSchlau : MonoBehaviour
{
public Transform target;
public float DampPosition = 10.0f;
public float DampRotation = 10.0f;
public void Update()
{
if (!target)
return;
var currentRotationAngleX = Mathf.LerpAngle(transform.eulerAngles.x, target.eulerAngles.x, DampRotation * Time.deltaTime);
var currentRotationAngleY = Mathf.LerpAngle(transform.eulerAngles.y, target.eulerAngles.y, DampRotation * Time.deltaTime);
var currentRotationAngleZ = Mathf.LerpAngle(transform.eulerAngles.z, target.eulerAngles.z, DampRotation * Time.deltaTime);
var curposX = Mathf.Lerp(transform.position.x, target.position.x, DampPosition * Time.deltaTime);
var curposY = Mathf.Lerp(transform.position.y, target.position.y, DampPosition * Time.deltaTime);
var curposZ = Mathf.Lerp(transform.position.z, target.position.z, DampPosition * Time.deltaTime);
if (float.IsNaN(curposX) || float.IsNaN(curposY) || float.IsNaN(curposZ))
{
return;
}
// if (Lookat == false) {
this.transform.localEulerAngles = new Vector3(currentRotationAngleX, currentRotationAngleY, currentRotationAngleZ);
this.transform.position = new Vector3(curposX, curposY, curposZ);
// } else {
// this.transform.LookAt(GameObject.Find("TargetSmooth").transform);
// this.transform.localPosition = Vector3(curposX, curposY, curposZ);
// SmoothRotation(target.position, rotDamp); }
}
//function SmoothRotation( targetPos : Vector3, rotSpeed : float ) {
// targetRot = Quaternion.LookRotation( targetPos - transform.position );
// transform.rotation = Quaternion.Slerp( transform.rotation, targetRot, Time.deltaTime*rotSpeed ); }
}
fileFormatVersion: 2
guid: 7a3776a5e0de9e543a055a253b67fc57
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment