It seems search doesn't work and don't know whether this issue has been already discussed.
I detect collisions between objects using "eventPairCreated". I need it to play a sound of impact. Is there is a robust way to detect a "impact" power. I use linear and angular velocities to detect whether influence was powerfull. But it works not very correct. Is there is some specific way to do it?
Power of a collision
Re: Power of a collision
Every CollidablePairHandler, a child class of NarrowPhasePair generated between two Collidables, has a Contacts collection. The contact data retrieved from the contact collection includes the original contact as well as things like accumulated normal impulse and relative velocity.
The accumulated normal impulse is the impulse that the engine applies each frame to keep the objects from penetrating, so it is the actual 'strength' of the collision. You could use that to modulate the volume of an impact. The relative velocity or friction impulse could be used to modulate sliding noises, too.
The event should have a pair passed into it. If you cast that pair to a CollidablePairHandler, you can access the contact collection.
The accumulated normal impulse is the impulse that the engine applies each frame to keep the objects from penetrating, so it is the actual 'strength' of the collision. You could use that to modulate the volume of an impact. The relative velocity or friction impulse could be used to modulate sliding noises, too.
The event should have a pair passed into it. If you cast that pair to a CollidablePairHandler, you can access the contact collection.
-
- Posts: 13
- Joined: Wed Aug 31, 2011 9:47 pm
Re: Power of a collision
Which event is more appropriate: ContactCreated or eventPairCreated ? Second occurs on the actual collision, but often CollidablePairHandler doesn't contain any contacts. "ContactCreated " occurs very often. It seems, e.g. that ball was collided with box only once, but this event is called 10 times.
What does mean more than one Contact in CollidablePairHandler? Should I sum them to get total impact?
Thanks for supporting.
What does mean more than one Contact in CollidablePairHandler? Should I sum them to get total impact?
Thanks for supporting.
Re: Power of a collision
Pair creation occurs when the axis aligned bounding boxes surrounding two shapes begin to overlap. This does not guarantee that contacts exist.
InitialCollisionDetected is probably the event you want. It only triggers when the contact count goes from 0 to something greater than 0.
However, if you wanted secondary impact sounds, then using a ContactCreated event would be necessary. Multiple contacts correspond to a collision surface instead of a single contact point, like a box sitting flatly on another box. The impact can be interpreted however you want- you could sum the forces and average the positions, or create a sound for each high-impact contact, or whatever else.
Another option would be to scan the contacts of each pair in the entity.CollisionInformation.Pairs collection outside of an event handler and decide what to do externally. You would have to manually reconstruct any logic like determining when to first play a sound.
InitialCollisionDetected is probably the event you want. It only triggers when the contact count goes from 0 to something greater than 0.
However, if you wanted secondary impact sounds, then using a ContactCreated event would be necessary. Multiple contacts correspond to a collision surface instead of a single contact point, like a box sitting flatly on another box. The impact can be interpreted however you want- you could sum the forces and average the positions, or create a sound for each high-impact contact, or whatever else.
Another option would be to scan the contacts of each pair in the entity.CollisionInformation.Pairs collection outside of an event handler and decide what to do externally. You would have to manually reconstruct any logic like determining when to first play a sound.
-
- Posts: 13
- Joined: Wed Aug 31, 2011 9:47 pm
Re: Power of a collision
Thanks a lot. "InitialCollisionDetected" is exactly what I need. You do really great job. Respect.