直接贴代码
using UnityEngine;
using System.Collections;
public class FllowTarget : MonoBehaviour {
public Transform target;
public float smoothTime = 0.01f;
private Vector3 cameraVelocity = Vector3.zero;
private Camera mainCamera;
void Awake ()
{
mainCamera = Camera.main;
}
void Update()
{
transform.position = Vector3.SmoothDamp(transform.position, target.position + new Vector3(0, 0, -5), ref cameraVelocity, smoothTime);
}
}
这里给一下Vector3.SmoothDamp的详解
Vector3.SmoothDamp 平滑阻尼
static function SmoothDamp (current : Vector3, target : Vector3, ref currentVelocity : Mathf.Infinity, deltaTime : float = Time.deltaTime) : Vector3
Parameters参数
current
当前的位置
target
我们试图接近的位置
currentVelocity
当前速度,这个值由你每次调用这个函数时被修改
smoothTime
到达目标的大约时间,较小的值将快速到达目标
maxSpeed
选择允许你限制的最大速度
deltaTime
自上次调用这个函数的时间。默认为 Time.deltaTime
Description描述
随着时间的推移,逐渐改变一个向量朝向预期的目标。
向量由一些像弹簧阻尼器函数平滑,这将永远不会超过。最常见的用途是平滑跟随相机。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)