我正在使用addforce
将物体扔向空中,我想在着陆点的位置实例化一个飞机,我该怎么做?我当时正在考虑使用Unity Physics API计算着陆点,但是我不知道如何。
我已经尝试了一些有关投射的代码,但无济于事
if (other.tag == "CarPlayer")
{
other.gameObject.GetComponentInParent<Rigidbody>().AddForce(0, 1 * power, 1 * power, ForceMode.Impulse);
}
我真的需要一种算法来找到物体要降落的实际点
答案 0 :(得分:0)
据我所知,您将必须自己做数学; Unity没有对此的内置即时模拟。
已经有很多在线资源,例如this wiki-page on Trajectory Simulation,这可能会为您提供帮助。
如果您需要计算力等(与您要的相反),请查看this blog,在此计算所需的轨迹。 Source code
最简单的答案可能是使用类似this的内容:
public Vector3 PlotTrajectoryAtTime (Vector3 start, Vector3 startVelocity, float time)
{
return (start) + (startVelocity * time) + (Physics.gravity * time * time * 0.5f);
}
(在开始解释PEMDAS之前;是的,我知道不需要括号,但是我认为视觉分组具有更好的可读性,因此更容易理解)