schteppe / p2.js

JavaScript 2D physics library
Other
2.64k stars 330 forks source link

body on BeginContact hasn't been emitted #296

Open jimmyyao88 opened 7 years ago

jimmyyao88 commented 7 years ago

I have 2 Kinematic body ,and also set the sensor property = true, while they contact each other , the body.on('beginContact',function()) hasn't been emitted ,why?

ghost commented 7 years ago

It looks like beginContact event is not triggered when 2 static or kinematic bodies overlaps. Look at Broadphase.canCollide function http://schteppe.github.io/p2.js/docs/files/src_collision_Broadphase.js.html#l118 This line says it all: if(bodyA.type === KINEMATIC && bodyB.type === KINEMATIC){ return false; } The simplest method I found to check if these 2 bodies overlaps is to run this function every frame world.narrowphase.bodiesOverlap(bodyA, bodyB)

jindingping commented 6 years ago

that should be world.on('beginContact',function()), and how do you set the sensor proeperty , i can't find that property