Jump to content

  • Log In with Google      Sign In   
  • Create Account

Playing sound in response to collisions


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 WFP   Members   -  Reputation: 826

Like
0Likes
Like

Posted 07 June 2014 - 03:55 PM

Hi,

 

I am currently trying to come up with a good solution for the situation where I have several collisions and want to play sounds in response to them.  With most aspects of the game, I can control with a degree of certainty when I play what sound, but for something as dynamic as the collision detection system, I'm a little stuck.  For example, say I have a large stack of boxes that I knock over.  I would like them to play small bumping-into-each-other sounds as they are falling and colliding with one another and with the floor.  The issue is that, especially once they have reached the floor but before the physics system (impulse based) has put them to sleep, they keep firing collision events and playing the sound as they make minuscule adjustments to their positions.

 

One solution I've come up with is to observe the velocity of the impacts and not play a sound below a certain threshold.  This could be extrapolated to include playing softer sounds at lower impact velocities until a final cutoff (so resting but not sleeping objects would still be silent), but there's a lot of trial-and-error involved in getting the thresholds exactly right.

 

Are there any more direct or obvious approaches to handling this type of situation that I'm overlooking, or is this the right track?



Sponsor:

#2 DiegoSLTS   Members   -  Reputation: 1897

Like
2Likes
Like

Posted 07 June 2014 - 05:58 PM

Maybe you can have a collection of pairs of objects that collided in one collision check and, for every collision detected in the next check, look if that pair of objects is in the pairs list. If the pair is NOT in the pairs list trigger the sound, if the pair is in the list do not trigger the sound, and if a pair of the list has not collided in the current collision check remove the pair, so if it's detected later it'll trigger the sound again.



#3 WFP   Members   -  Reputation: 826

Like
0Likes
Like

Posted 07 June 2014 - 06:16 PM

Good suggestion, DiegoSLTS.  That seems like it would solve the resting contacts problem well.  I'll try it out.



#4 SeanMiddleditch   Members   -  Reputation: 7178

Like
2Likes
Like

Posted 07 June 2014 - 11:28 PM

If the pair is NOT in the pairs list trigger the sound, if the pair is in the list do not trigger the sound, and if a pair of the list has not collided in the current collision check remove the pair


You generally want to do this most of the time so that you can send OnCollisionEntered and OnCollisionExited events (or whatever you want to call them). Aside from just sounds, there's tons of game events that need to react differently between these events and OnCollisionMaintained.

#5 WFP   Members   -  Reputation: 826

Like
0Likes
Like

Posted 08 June 2014 - 09:23 AM

Sean, that's also a good suggestions and mixes in fluidly with the setup I've created according to Diego's initial suggestion, as well as my existing event management system.  Thanks for the tip!






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS