p2.js
p2.js copied to clipboard
Sensor contact events with other sensors or static bodies (active sensors)
I had a situation where I needed a sensor that follows my player and needed contact events from this sensor with whatever hits it, including static bodies and other sensors.
I did found a solution, but it sounds like a hack to me:
- I created body with a Body.mass > 0
- Added a regular sensor shape to this body with (shape.sensor=true)
- I explicitly set the position of the sensor each frame so it does not get moved by gravity
- I now receive the collision events with other sensors and static bodies
It would be nice if we could make a sensor active to trigger all collisions, against static bodies, but with no gravity influence. Not sure of the syntax tho...
Hi, If you clone and build the latest version, you can now use body.collisionResponse. Set it to false and collisions with this body will do nothing. However, they will trigger all ordinary contact events and such.
It also works for shapes :)
Stefan