很多时候,我们为了在游戏中更好的实现某一缓动效果,都要利用到插值。举个栗子,相机跟随人物,如果只是单纯的绑定相互关系,那么实现出来的效果肯定很生硬,但我们加入插值计算之后,就能很好地实现镜头的缓冲效果。
public static Vector3 Lerp(Vector3 a, Vector3 b, float t);
//public Transform trans_1; public Transform trans_2; public float speed; private float timer; // Use this for initialization void Start () { } // Update is called once per frame void Update () { this.transform.position = Vector3.Lerp(transform.position, trans_2.position, speed); }
public Transform point1; public Transform point2; public Vector3 vec3; // Use this for initialization void Start () { } // Update is called once per frame void Update () { for (int i = 0; i < 11; i++) { Debug.DrawLine(vec3, Vector3.Slerp(point1.position, point2.position, i*0.1f), Color.red); } }
效果图: