代码计算抛物线

来源:互联网 发布:.net framework mac版 编辑:程序博客网 时间:2024/05/05 11:40
public class GTool{        // 计算抛物线        static public Vector3 getPoint(Vector3 start,Vector3 end,float t, float hight){        Vector3 value = Vector3.Lerp (start, end,t); // x z 轴上的线性位移        value.y = Mathf.Lerp(0,hight,Mathf.Sin(t*Mathf.PI)); // y 轴上的sin 抛物线位移        return value;    }}public class Main : MonoBebavior{    public float time; // 时间 (0到1之间)    public float height; // 抛物线高度    void Update(){    target.position = GTool.getPoint(start, end, time, height);}}

直接将Main类挂到物体上。

原创粉丝点击