两个物体,都添加了RigidBody和PhysicsBoxCollider,其中一个物体不动的物体Rigidbody type=静态,另一个移动的是动态
enabledContactListener=true,bullet=true;
碰撞的回调函数
onPreSolve: function (contact, selfCollider, otherCollider) {
console.log(‘contact’, contact);
console.log(‘selfCollider’, selfCollider);
console.log(‘otherCollider’, otherCollider);
},
只有第一次碰撞会不穿透过去,后面再碰撞移动的物体会直接穿透静止的物体,
你勾选了“Allow Sleep”的问题,第一次碰撞后,刚体没有受到任何外力,同时速度为0,因此进入sleep,你的touchmove只是去改变的节点的坐标,并没有改变刚体的受力情况或者是速度,因此刚体一直处于sleep,所以不会再与静态刚体进行碰撞的检测。
解决办法1:Allow Sleep不勾选
解决办法2:TouchMove里面加入代码
this.node.on('touchmove', function (event) {
var touch = event.touch;
var pos = touch.getDelta();
this.protect.getComponent(cc.RigidBody).awake = true;
this.protect.x += pos.x;
this.protect.y += pos.y;
}, this);
好的,谢谢
还有个问题,除了用selfCollider和otherCollider中的名字判断碰撞的节点之外,还有没有简单点的判断方法,比如说碰撞的分组
物理系统的碰撞回调参数就这几个,不管是name还是GroupIndex都是节点的属性,都把节点传过来了,取哪个属性取判断就是逻辑上面的事情了,不太明白你的需求
好的,我知道了