兩點(diǎn)之間移動的方法
(1)Lerp函數(shù)
注意事項(xiàng):如果想A點(diǎn)直接到B點(diǎn)那么T就應(yīng)該是1迹蛤,T的取值0-1碘菜。
void Update()
{
t1 += 1f * Time.deltaTime;
transform.position = Vector3.Lerp(開始, 到達(dá), t1);
}
(1)SmoothDamp函數(shù)
注意事項(xiàng):velocity一定要定義為全局變量。
private Vector3 target = new Vector3(0, 0, 5);
public float smoothTime = 0.5F;
private Vector3 velocity = Vector3.zero;
void Update()
{
transform.position = Vector3.SmoothDamp(transform.position, target, ref velocity, smoothTime);
}