天天看點

Unity Vector3.Lerp

一、勻速運動

public Transform from;
    public Transform to;
    public float mMoveTime = f;

    private float t = f;
    void Update()
    {
        t += f / mMoveTime * Time.deltaTime;
        from.position = Vector3.Lerp(from.position, to.position, t);
    }
           

二、彈簧運動

public Transform from;
    public Transform to;
    public float mLerpRate = f;

    private float t;
    void Update()
    {
        t = mLerpRate * Time.deltaTime;
        from.position = Vector3.Lerp(from.position, to.position, t);
    }