[英]How to cap velocity in Unity 3D using AddForce with ForceMode.VelocityChange
[英]ForceMode.VelocityChange change is so dramatic
所以我正在制作一个运动脚本,这是 class 的内部:
// This is a reference to the Rigidbody component called "rb"
public Rigidbody rb;
public float forwardForce = 500f;
public float sidewaysForce = 0.01f;
// We marked this as "Fixed"Update because we
// are using it to mess with physics.
void FixedUpdate()
{
// Add a forward force
rb.AddForce(0, 0, forwardForce * Time.deltaTime);
if ( Input.GetKey("d") )
{
rb.AddForce(sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
if ( Input.GetKey("a") )
{
rb.AddForce(-sidewaysForce * Time.deltaTime, 0, 0, ForceMode.VelocityChange);
}
}
玩家所在的矩形平面的宽度为 15,玩家位于中间。 但是由于某种原因,当我按下“a”时,玩家会缩小飞机。 这也在另一边发生。
Input.GetKey当用户按住由名称标识的键时返回 true。 当您在更新中执行rb.AddForce
时,您可能会以非常高的频率执行此操作,因此力会累加并使运动突然发生。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.