繁体   English   中英

如何使用刚体的 AddForce 设置恒定速度?

[英]How can I set a constant speed with AddForce of the rigidbody?

我想用 AddForce 移动 object 但我不希望它的速度急剧增加,没有限制,而是以浮点值设置的速度限制移动。

您可能会使用Vector3.ClampMagnitude

rigidbody.AddForce(...);

float maxSpeed = 10;
rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, maxSpeed);

并且不要忘记在FixedUpdate()中而不是在Update()中使用力

您可以使用钳位来限制您的值;

https://docs.unity3d.com/ScriptReference/Mathf.Clamp.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM