刚体 (Rigidbody) 是实现游戏对象的物理行为的主要组件。连接刚体后,对象将立即响应重力。如果还添加了一个或多个__碰撞体__组件,则游戏对象会因发生碰撞而移动。
由于刚体组件会接管附加到的游戏对象的运动,因此不应试图借助脚本通过更改变换属性(如位置和旋转)来移动游戏对象。相反,应该施加__力__来推动游戏对象并让物理引擎计算结果。
在某些情况下,可能希望游戏对象具有刚体,并让刚体的运动摆脱物理引擎的控制。例如,可能希望直接从脚本代码控制角色,但仍允许触发器检测角色(请参阅碰撞体主题下的_触发器_)。脚本产生的这种非物理运动称为_运动学_运动。刚体组件有一个名为 Is Kinematic 的属性,该属性可以让刚体摆脱物理引擎的控制,并允许通过脚本以运动学方式来移动刚体。可以通过脚本来更改 Is Kinematic 的值,从而为某个对象开启和关闭物理引擎,但这会产生性能开销,应谨慎使用。
有关这些组件的设置和脚本选项的更多详细信息,请参阅刚体和 2D 刚体参考页面。
当刚体移动速度低于规定的最小线性速度或转速时,物理引擎会认为刚体已经停止。发生这种情况时,游戏对象在受到碰撞或力之前不会再次移动,因此将其设置为“睡眠”模式。这种优化意味着,在刚体下一次被“唤醒”(即再次进入运动状态)之前,不会花费处理器时间来更新刚体。
在大多数情况下,刚体组件的睡眠和唤醒是透明发生的。但是,如果通过修改__变换__位置将静态碰撞体(即,没有刚体的碰撞体)移入游戏对象或远离游戏对象,则可能无法唤醒游戏对象。这种情况下可能会导致问题,例如,已经从刚体游戏对象下面移走地板时,刚体游戏对象会悬在空中。在这种情况下,可以使用 WakeUp
函数显式唤醒游戏对象。有关睡眠的更多信息,请参阅刚体和 2D 刚体组件页面。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.