看一个小游戏的源码时的时候,看到有这么一句代码:
GetComponent<Rigidbody>().WakeUp ();
愣了一下,去官网查了一下API,它的意思唤醒一个沉睡的Rigidbody,难道刚体也能睡觉?对呀,因为这是为了优化。
那,原话是这么说的:When a Rigidbody is moving slower than a defined minimum linear or rotational speed, the physics engine assumes it has come to a halt. When this happens, the GameObject does not move again until it receives a collision or force, and so it is set to “sleeping” mode. This optimisation means that no processor time is spent updating the Rigidbody until the next time it is “awoken” (that is, set in motion again).
大白话翻译:当一个刚体比定义的最小线性速度或者旋转速度小时,物理引擎就会假定刚体暂时不使用,直到接受了一个碰撞或者外力,否则就进入了睡眠状态,会节约性能。
那,如果睡眠了,会发生什么?bug!!!
且看下一段原话(准确的描述了bug如何产生):For most purposes, the sleeping and waking of a Rigidbody component happens transparently. However, a GameObject might