I want to set my current velocity to zero on event trigger. I am using p2.js integration so rigidBody won’t work. Please help:
https://playcanvas.com/editor/scene/1072109
Hi @mortal_phoenix,
To set a p2.js body to act as a trigger set the Sensor option to true:
From there you can use the following method to listen to contact events and filter your trigger e.g. with its name:
// --- this should be added to a script attached to your p2 World entity
this.entity.script.p2World.world.on("beginContact",function(evt){
if( evt.bodyA.entity.name === 'Trigger' || evt.bodyB.entity.name === 'Trigger'){
// set velocity to zero
}
}, this);
This tutorial explains, among other things, how p2 physics work:
1 Like