
这个属性说的是:如果此刚体永远都不应该进入睡眠,那么设置这个属性为 False。需要注意这将使 CPU 占用率提高,文档地址:Cocos Creator API
休眠:意思应该就是只展示ui效果,没有碰撞检测了,我的老天,cocos的人怎么想的,我为什么要使用刚体你不知道吗?我就是需要碰撞检测啊,你现在到好,直接给我睡眠,还是默认的,我怎么说搞了那么久,只有子弹发射出来的一下有碰撞,后面就没有了..........真的不至于默认给true啊,应该默认给false,等别人真的需要只检测一下的时候,再来设置为ture啊
还有这个碰撞回掉......我肯定是想使用碰撞的,大部分情况都是要回掉的吧,结果你到好,又给了默认false........需要勾选为true才有回掉函数:

注册回调函数
注册一个碰撞回调函数有两种方式,一种是通过指定的 collider 注册;另一种是通过 2D 物理系统注册一个全局的回调函数。
注意 :Builtin 2D 物理模块只会发送 BEGIN_CONTACT
和 END_CONTACT
回调消息。
javascript
@ccclass('TestContactCallBack')
export class TestContactCallBack extends Component {
start () {
// 注册单个碰撞体的回调函数
let collider = this.getComponent(Collider2D);
if (collider) {
collider.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
collider.on(Contact2DType.END_CONTACT, this.onEndContact, this);
}
// 注册全局碰撞回调函数
if (PhysicsSystem2D.instance) {
PhysicsSystem2D.instance.on(Contact2DType.BEGIN_CONTACT, this.onBeginContact, this);
PhysicsSystem2D.instance.on(Contact2DType.END_CONTACT, this.onEndContact, this);
}
}
onBeginContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 只在两个碰撞体开始接触时被调用一次
console.log('onBeginContact');
}
onEndContact (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 只在两个碰撞体结束接触时被调用一次
console.log('onEndContact');
}
onPreSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 每次将要处理碰撞体接触逻辑时被调用
console.log('onPreSolve');
}
onPostSolve (selfCollider: Collider2D, otherCollider: Collider2D, contact: IPhysics2DContact | null) {
// 每次处理完碰撞体接触逻辑时被调用
console.log('onPostSolve');
}
}