Unity使用DoTween实现抛物线效果
Unity使用DoTween实现抛物线效果,供大家参考,具体内容如下
概要
public partial class EMath { public static Vector3 Parabola(Vector3 start, Vector3 end, float height, float t) { float Func(float x) => 4 * (-height * x * x + height * x); var mid = Vector3.Lerp(start, end, t); return new Vector3(mid.x, Func(t) + Mathf.Lerp(start.y, end.y, t), mid.z); } public static Vector2 Parabola(Vector2 start, Vector2 end, float height, float t) { float Func(float x) => 4 * (-height * x * x + height * x); var mid = Vector2.Lerp(start, end, t); return new Vector2(mid.x, Func(t) + Mathf.Lerp(start.y, end.y, t)); } }
使用方法
public class Test : MonoBehaviour { public Transform start; public Transform target; public Transform ball; private float t; private void Start() { DOTween.To(setter: value => { Debug.Log(value); ball.position = Parabola(start.position, target.position, 10, value); }, startValue: 0, endValue: 1, duration: 5) .SetEase(Ease.Linear); } }
效果演示
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持我们。
赞 (0)