查看: 2667|回复: 0
打印 上一主题 下一主题

[Unity 组件参考手册]脚本概念之刚体休眠

[复制链接]
.    

3797

主题

11

听众

5万

积分

首席设计师

Rank: 8Rank: 8

纳金币
32328
精华
41

活跃会员 优秀版主 荣誉管理 论坛元老

跳转到指定楼层
楼主
发表于 2013-2-26 17:40:22 |只看该作者 |倒序浏览
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/
分享到: QQ好友和群QQ好友和群 腾讯微博腾讯微博 腾讯朋友腾讯朋友 微信微信
转播转播0 分享淘帖0 收藏收藏0 支持支持0 反对反对0
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

手机版|纳金网 ( 闽ICP备2021016425号-2/3

GMT+8, 2024-11-16 04:46 , Processed in 0.100462 second(s), 31 queries .

Powered by Discuz!-创意设计 X2.5

© 2008-2019 Narkii Inc.

回顶部