Skip to content

Instantly share code, notes, and snippets.

@gsomoza
Forked from damian-pastorini/P2JS
Last active February 14, 2019 08:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gsomoza/5506e492adc0da51106ae4674920455e to your computer and use it in GitHub Desktop.
Save gsomoza/5506e492adc0da51106ae4674920455e to your computer and use it in GitHub Desktop.
My first P2 impact test code....
this.p2world.on('impact', function(evt){
var playerBody,
currentPlayer = this.state.players[client.sessionId];
console.log('Body positions: ', evt.bodyA.position, evt.bodyB.position);
if (evt.bodyA.hasOwnProperty('playerId')) {
playerBody = evt.bodyA;
} else if (evt.bodyB.hasOwnProperty('playerId')) {
playerBody = evt.bodyB;
} else {
console.log('who the fuck is moving???');
return;
}
console.log('Player ID:' + playerBody.playerId);
playerBody.velocity = [0, 0];
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment