using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Vector3Moved : MonoBehaviour
{
public Transform target;
public Transform A;
public Transform B;
private Vector3 startPos;
public Transform C;
private float time;
private Vector3 nowTarget;
// Start is called before the first frame update
void Start()
{
startPos = B.position;
}
// Update is called once per frame
void Update()
{
//先快后满 每帧改变Start位置,位置无限接近,但不会得到end位置
A.position = Vector3.Lerp(A.position, target.position, Time.deltaTime);
//匀速 每帧改变事件 当t>=1时 得到结果
//这种匀速移动 当time>=1时, 我改变了目标位置后,它会直接瞬移到我们的目标位置
if(nowTarget!=target.position)
{
nowTarget = target.position;
time = 0;
startPos = B.position;
}
time += Time.deltaTime;
B.position = Vector3.Lerp(startPos, target.position, time);
//球形插值
C.position = Vector3.Slerp(Vector3.right * 10, Vector3.forward*10, time * 0.1f);
}
}
主要时Unity Slerp和Lerp之间的区别