Playground: https://playground.babylonjs.com/#Z8HTUN#307
In my project, I need to know when to trigger events based on collision results. For example, when to play a crashing sound when two objects collide. But the incoming collision information isn’t very helpful in making the decision to trigger these events – unless I’m misinterpreting something. Keep in mind, the above playground is obviously simple, but in my project I have multiple convex hulls interacting with each other.
When I get collisionEvent info in the collision callback, it tells me the basics about who hit whom, and where, and the normal. It also has a distance
field, which seems to be how far into the plane of intersection the contact point is. I have been trying to use Math.abs(distance)
as an indicator of the seriousness of the collision, but it’s not always reliable. Sometimes the distance field seems almost random. Sometimes a mathematically deep intersection with a large distance (greater than 1.0, say) only looks like a gentle brushing against each other on the screen. And conversely, sometimes a strong visual collision on the screen only shows a small distance value. This leads to me playing big crashing sounds with apparently nothing is happening on the screen, OR playing no sound at all when a visually interesting collision is happening on the screen.
So my question is: is there another way to interpret the collisionEvent info so that I can reliably make decisions on what is an important collision vs. an unimportant one? And also, is it possible in the future to get more information from the Havok plugin about the nature of the collision? For example, I’d love to know the linear and angular velocities of bodies A and B at the time of impact and also how those velocities will change after the impact. Thanks for any feedback!
edit: I should mention I am only requesting collision callbacks for hk._hknp.EventType.COLLISION_STARTED.value
but still I seem to get many collisions for the same body in a single frame. Maybe because the bodies are overlapping a bit? Is it firing one callback for each vertex of the convex hull that is intersecting? Also, when I call hitterBody.getLinearVelocityToRef()
at the time of collision, the returned velocity and the distance
field are rarely in agreement about how serious the collision is. (Sometimes the distance is small while the velocity is large and vice versa)