x


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.alt text

Or the pic - http://i47.tinypic.com/2wqcy6e.jpg

  • Thanks.
more ▼

asked Jun 24 '12 at 04:40 AM

mixwell gravatar image

mixwell
2 1 1 2

dude are you on soundsnap ?

Jun 24 '12 at 10:00 AM Fattie

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.

Jun 24 '12 at 10:17 AM mixwell

Mix -- I just meant: since you are a sound designer, do you sell YOUR sound design work on http://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.

Jun 24 '12 at 10:39 AM Fattie

oh. no i don't sell sfx there, however i am planning to do that soon.

and thanks for the tip.

Jun 25 '12 at 05:38 AM mixwell
(comments are locked)
10|3000 characters needed characters left

3 answers: sort voted first
more ▼

answered Jun 24 '12 at 04:46 AM

alucardj gravatar image

alucardj
13.7k 34 56 87

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 SendMessage would be a good idea. Light be hard if your not a programmer though.

Jun 24 '12 at 05:18 AM Berenger

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.GetMouseButtonUp(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 ....)

Jun 24 '12 at 07:09 AM alucardj

thank you . i will try this and the other Raycast thing soon.

Jun 24 '12 at 10:20 AM mixwell
(comments are locked)
10|3000 characters needed characters left

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.

more ▼

answered Jun 24 '12 at 05:39 AM

TheDavil86 gravatar image

TheDavil86
38 3 5 6

I can try ! thanks

Jun 24 '12 at 05:52 AM mixwell
(comments are locked)
10|3000 characters needed characters left

@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.

more ▼

answered Jun 24 '12 at 05:39 AM

mixwell gravatar image

mixwell
2 1 1 2

hi there, I have added a comment to my answer ( am Jay Kay =] ), please post comments using the comments tab [add new comment] under the answer.

Jun 24 '12 at 07:11 AM alucardj
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1027
x10
x9

asked: Jun 24 '12 at 04:40 AM

Seen: 603 times

Last Updated: Jun 25 '12 at 05:38 AM