- Home /
How to create impact sounds?
Hi,
This is the first time i am using the Unity dev kit. I am a sound designer.
Now the question - How to create impact sounds in Unity ? I searched a bit but could not find an answer.
What i am trying to do is add a sound to the barrel when player fires the gun at it.
*What i ended up doing is this (which is not what i want) - http://www.mediafire.com/?y48bfxt5hb9ey2m
Please check the attachment.
Or the pic - http://i47.tinypic.com/2wqcy6e.jpg
Thanks.
no i don't have a soundsnap account. its for sfx right?
i don't need the actual sound files if thats what you mean.
$$anonymous$$ix -- I just meant: since you are a sound designer, do you sell YOUR sound design work on SoundSnap.com ?
in answer to your question here. Are you familiar with the "Components" in Unity?
Your barrel will be a "GameObject".
What you want to do is add a "Component" to the barrel game object. In fact, what you'll want ot add is an "Audio Source".
Look at the AudioSource you have just added.
Notice - for example - there is a button "AutoPlay". try that. Whenever you launch, it will play. that's not what you want.
Now, you're going to have to learn a little scripting. You are comfortable with this? you will have to add a SCRIPT to the BARREL "game object". You write the scriupt and then drag it on. basically the script will say "when there is a collision, AudioSource.Play()" it's very easy if you're comfortable scripting.
Hope it helps, and ask anything.
oh. no i don't sell sfx there, however i am planning to do that soon.
and thanks for the tip.
Answer by AlucardJay · Jun 24, 2012 at 04:46 AM
http://unity3d.com/support/documentation/Manual/Sound.html
http://unity3d.com/support/documentation/Components/class-AudioListener.html
http://unity3d.com/support/documentation/Components/class-AudioSource.html
http://unity3d.com/support/documentation/ScriptReference/AudioSource.html
http://www.unity3dstudent.com/2010/07/beginner-b10-audio-basics/
He also needs a mechanism. I don't know how the fire is handled in that game, but if bullets are instantiated you'll need to create a script that implement OnCollisionEnter, and if it's a Raycast you'll need to find where it's done and call a function there. A Send$$anonymous$$essage would be a good idea. Light be hard if your not a programmer though.
sry, was in a rush when I posted the links. Hopefully the docs were useful reading. I should've added you could get the hit position of a raycast (as @TheDavil86 suggested), then use AudioSource.PlayClipAtPoint at that position. This should be easy to add if you are using a raycast for the bullet, and for adding any effect at the point of impact (particle effect, audio). e.g.:
public var impactClip : AudioClip;
function Update()
{
if (Input.Get$$anonymous$$ouseButtonUp(0))
{
var ray = Camera.main.ScreenPointToRay( Input.mousePosition );
var hit : RaycastHit;
if ( Physics.Raycast(ray, hit, 100) )
{
AudioSource.PlayClipAtPoint( impactClip, hit.point );
}
}
}
Though I would consider instantianting an object at the impact point that includes a particle effect and audio clip (2 birds ....)
thank you . i will try this and the other Raycast thing soon.
Answer by TheDavil86 · Jun 24, 2012 at 05:39 AM
You'll need to instantiate a sound at the collision point of the raycast.
If you look at how the shooting code works you'll see there is a Physics.Raycast call. The 3rd argument in that function is usually tied to a variable of type RaycastHit. That RaycastHit variable will give you the position of the collision. And that's where you need to instantiate the sound.
I'd just give you the code for it, but then you wouldn't really learn anything.
Answer by mixwell · Jun 24, 2012 at 05:39 AM
@Jay Kay
Thank you for that and i actually watched that JDAMS video before posting this. I applied that to my project but what it does it Play a sound when player "touches" the object.
But what i am trying to create is impact (or collision in unity terms?) sounds. the impact is supposed to be the bullet which the player fires at the object.
hi there, I have added a comment to my answer ( am $$anonymous$$ $$anonymous$$ay =] ), please post comments using the comments tab [add new comment] under the answer.
Your answer
Follow this Question
Related Questions
One Slider Control More Than One Sound 1 Answer
Button doesn't play sound after different button press 0 Answers
Separate Listeners for Sound FX and Music? 0 Answers
Sound plays right at the beginning 2 Answers
Problems with a racing game level. 0 Answers