I have two Cannon.js Objects, and have attached the "collide" event listener to both.
carBody.addEventListener("collide",function(e){
});
I want to be able to react differently depending on how much force the collision has is there a way to do this?
You can get the relative velocity in the contact point to determine the amount of energy in the collision. Example:
carBody.addEventListener("collide",function(e){
var relativeVelocity = e.contact.getImpactVelocityAlongNormal();
if(Math.abs(relativeVelocity) > 10){
// More energy
} else {
// Less energy
}
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With