p2 add-on for bodies that detect collision but have no collision response.
A ghost body will not bounce off of or have friction with other bodies. You can still react to a ghost overlapping other bodies via World's beginContact event.
Ghost bodies fire events when other bodies enter/exit them.
var ghostBody = require('ghost-body');
Enables a World to have ghost bodies. Call this once per World.
Disables ghost bodies in a World.
Turn on ghost mode for a Body. Call this once on every Body that needs ghost treatment.
Turn off ghost mode for a Body.
See if Body is a ghost.
Events are fired by ghost bodies using p2's built-in event system.
Fired when a body enters a ghost body.
ghost.on('bodyEntered', function(event) {
// number of bodies currently overlapping ghost
event.count
// body that entered
event.causedBy
});
Fired when a body enters a ghost body that was empty. Fired before coinciding bodyEntered event.
ghost.on('populated', function(event) {
// number of bodies currently overlapping ghost
event.count
// body that entered
event.causedBy
});
Fired when a body leaves a ghost body.
ghost.on('bodyExited', function(event) {
// number of bodies currently overlapping ghost
event.count
// body that exited
event.causedBy
});
Fired when the last body leaves a ghost body. Fired before coinciding bodyExited event.
ghost.on('emptied', function(event) {
// number of bodies currently overlapping ghost
event.count
// body that exited
event.causedBy
});
npm install ghost-body
MIT