- 最后登录
- 2018-12-19
- 注册时间
- 2012-8-20
- 阅读权限
- 90
- 积分
- 54706
- 纳金币
- 32328
- 精华
- 41
|
When Rigidbodies fall to rest - a box landing on the floor - they will start sleeping. Sleeping is an optimization which allows the Physics Engine to stop processing those rigidbodies. This way you can have huge amounts of rigidbodies in your scene as long as you make sure that they normally don't move. 当刚体空闲时,如一个掉到地板上的盒子,他们就会开始休眠。休眠是性能优化的一个策略,即物理引擎不会处理那些处于休眠中的刚体。这样一来,只要某刚体在正常情况下不移动,那么你可以在你的场景中添加大量的该刚体。Rigidbody sleeping happens completely automatically. Whenever a rigidbody is slower than the sleepAngularVelocity and sleepVelocity it will start falling asleep. After a few frames of resting it will then be set to sleep. When the body is sleeping, no collision detection or simulation will be performed anymore. This saves a lot of CPU cycles. 刚体休眠完全自动发生。只要刚体的速度低于sleepAngularVelocity和sleepVelocity,该刚体就会开始休眠。其空闲一些帧后,就会被设置成休眠状态。处于休眠状态中的物体,不会再对其进行碰撞检测和模拟。这会节约大量的CPU开销。Rigidbodies automatically wake up when: 刚体在以下情况中会被自动唤醒:another rigidbody collides with the sleeping rigidbody
其他的刚体碰撞器作用于休眠的刚体 another rigidbody connected through a joint is moving.
被其他的刚体通过移动的关节连接when modifying a property of the rigidbody
修改了刚体的属性when adding forces.
当添加外力时 So if you want to make rigidbodies fall to rest, don't modify their properties or add forces when they are about to go into sleep mode. 所以如果你想使进入睡眠,那么在他们将要进入休眠模式时不要更改他们的属性或者添加任何外力。There are two variables that you can tune to make sure your rigidbodies automatically fall to rest: Rigidbody.sleepVelocity and Rigidbody.sleepAngularVelocity. Those two variables are initialized to the sleepVelocity and sleepAngularVelocity variable defined in the Physics Manager (Edit -> Project Settings -> Physics). 你可以调节两个变量来确保刚体自动进入睡眠,这两个变量是:Rigidbody.sleepVelocity和 Rigidbody.sleepAngularVelocity。这两个变量的初始值即分别为物理管理器中的sleepVelocity和 sleepAngularVelocity的值(编辑->项目设置->物理)。Rigidbodies can also be forced to sleep using rigidbody.Sleep. This is useful to start rigidbodies in a rest state when loading a new level. 当然还可以通过rigidbody.Sleep强制使刚体睡眠。当加载新的关卡时,从睡眠状态启动刚体,对整个系统很有帮组。Kinematic rigidbodies wake up sleeping rigidbodies. Static Colliders do not. If you have a sleeping rigidbody and you move a static collider (A collider without a Rigidbody attached) into the rigidbody or pull it from underneath the rigidbody, the sleeping rigidbody will not awake. If you move a Kinematic Rigidbody out from underneath normal Rigidbodies that are at rest on top of it, the sleeping Rigidbodies will "wake up" and be correctly calculated again in the physics update. So if you have a lot of Static Colliders that you want to move around and have different objects fall on them correctly, use Kinematic Rigidbody Colliders. 处于运动状态中的刚体能唤醒休眠中的刚体。静态碰撞器不能唤醒休眠中的刚体。即如果你将一个静态碰撞器(没有和任何刚体绑定过)绑定到处于休眠中的刚体,或者将静态碰撞器抽离处于休眠中的刚体时,这个休眠中的刚体是不会被唤醒的。但是如果你将一个运动中的刚体从它所属的且处于休眠状态中的顶层刚体移出时,处于休眠中的刚体将会被唤醒,且会在图形更新里被重新正确的计算。所以如果你有大量的静态碰撞器需要移除或添加,同时在它们上面正确地绑定不同的对象,就请使用运动刚体控制器吧。Kinematic rigidbodies - they will not be calculated during the physics update since they are not going anywhere. If you move a Kinematic Rigidbody out from underneath normal Rigidbodies that are at rest on top of it, the sleeping Rigidbodies will "wake up" and be correctly calculated again in the physics update. So if you have a lot of Static Colliders that you want to move around and have different objects fall on them correctly, use Kinematic Rigidbody Colliders. 如果运动刚体不进行运动,那么它们将不在物体更新时参与计算。如果你将一个运动中的刚体从它所属的且处于休眠状态中的顶层刚体移出时,处于休眠中的那个刚体将会被唤醒,且会在图形更新里被重新正确的计算。所以如果你有大量的静态碰撞器需要移除或添加,同时在它们上面正确地绑定不同的对象,就请使用运动刚体控制器吧。 【来源:互联网】
更多精彩教程,尽在web3D纳金网http://www.narkii.com/college/ |
|