sound on collision

Hello
I have just figured out how to use the collision handler and when objects collide with each other they get pushed out of the way. However I have tried unsuccessfully to write some code so that when the objects meet a sound is played to indicate a collision but got very confused.

So can anyone point me in the right direction towards writing correct code so that my program will run.
What I think I have to do is some how connect the traverser and playing of the sound together but not sure how.
can anyone help?

I suspect that what you want is CollisionHandlerEvent.

From what you say, am I correct in guessing that you are currently using CollisionHandlerPusher? If so, then it’s pretty easy: since, I believe, CollisionHandlerPusher inherits from CollisionHandlerEvent, you should be able to simply treat your CollisionHandlerPusher as though it were a CollisionHandlerEvent and register appropriate events for it, as shown, I believe, on the page that I first linked to in this post. :slight_smile:

Hi there Thaumaturge
thanks again for a reply
So I have figured out the collision process and I have loaded the appropriate sound I want to trigger when an object gets hit. However I do not know how to write the code to make this happen it is like you said I can treat the CollisionHandlerPusher as though it were a CollisionHandlerEvent to register appropriate events for it.

I tried to attach the sound to the collision node which sort of worked for example the sound was played once. This happened because I purposely did not loop it because the sound is only meant to be played every time the objects collide which did not happen anyway

So do I have use and if / else statement for example if the object hits another object play the sound
else if there is no contact don’t play the sound

In other words I do not know the appropriate statements, commands or functions to use so if you could point me in the right direction I would really appreciate it and thanks for your patients for helping a newbie

No, I don’t think that you’re going about it correctly, I’m afraid. :confused:

You say that you’ve managed to register an event; in the method called by that event, simply tell your sound to play once. This should cause the sound to play whenever the event is called, which should be whenever the appropriate collision occurs. If you’re getting the sound playing for other collisions, then you should be able to fix it be either constructing your event more restrictively or checking that the relevant objects are involved in the event.