Reputation: 41
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?
Upvotes: 4
Views: 2805
Reputation: 2084
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
}
});
Upvotes: 6