版权声明:本文为博主原创文章,转载请表明来源和网址。 https://blog.csdn.net/thinbug/article/details/89469656
按时间计算抛物线轨迹
public float time = 2; //代表从A点出发到B经过的时长
public Transform point; //点(移动的)
public Transform pointA;//点A(开始位置)
public Transform pointB;//点B(结束位置)
public Transform pointT;//点T
public float g = -10;//重力加速度
private Vector3 speed;//初速度向量
private Vector3 Gravity;//重力向量
void Start()
{
}
public int stat = 0; //改成1就开始
float begintime; //开始时间
void Update()
{
if (stat == 1)
{
stat = 0;
//速度中间速度
speed = new Vector3((pointB.position.x - pointA.position.x) / time,
(pointB.position.y - pointA.position.y) / time - 0.5f * g * time, (pointB.position.z - pointA.position.z) / time);
begintime = Time.time;
pointT.position = speed;
}
float pass = Time.time - begintime;
Gravity.y = 0.5f * g * pass * pass; //v = 1/2gt²
point.transform.position = pointA.position + speed * pass + Gravity ;
}
参考:http://www.cnblogs.com/jqg-aliang/p/4806017.html