Adding Footstep Sounds to your Unity game with Animation Events

Adding Footstep Sounds to your Unity game with Animation Events

Jason Weimann

6 лет назад

97,194 Просмотров

Ссылки и html тэги не поддерживаются


Комментарии:

Mateo p
Mateo p - 07.08.2023 03:49

i clicked for the cute feet.

Ответить
Eric el Nomada
Eric el Nomada - 10.07.2023 23:02

This solution is very cheap, instead you should use Scriptable Objects and a Surface Manager

Ответить
DEXTRA VISUAL
DEXTRA VISUAL - 09.07.2023 23:44

Works in a regular scene but in VR I always get a no Receiver error.

Ответить
FL
FL - 04.05.2023 14:23

I cannot see events at all in the inspector. I cannot find that option. I am not sure what I am missing.. Can someone help?

Ответить
Renown
Renown - 03.11.2022 12:39

I was stressing about how I could implement this, and your video makes it so simple. Thank you :)

Ответить
Fon Gaming 101
Fon Gaming 101 - 13.10.2022 05:05

beautiful, stole your idea for my 2d platformer, its very similar, thanks j!

Ответить
SangHoon Lim
SangHoon Lim - 23.08.2022 10:29

How can I use Terran Director?
This video didn't describe that.

Ответить
SangHoon Lim
SangHoon Lim - 23.08.2022 09:40

How can I do this in 2021.3.6f Version?
The interface looks different.

Ответить
GG人
GG人 - 10.07.2022 16:51

very useful my footstep sound good now thx

Ответить
Scott Beowulf Kaine
Scott Beowulf Kaine - 25.05.2022 00:29

Thank you this helped me!

Ответить
Willskull
Willskull - 04.02.2022 14:39

Nothing happens, I wrote everything in the script just the same yet nothing happens :(

Ответить
Potato ML
Potato ML - 28.01.2022 19:39

awesome tuts

Ответить
Howchen
Howchen - 09.01.2022 20:58

is there a way to do this for 2d footsteps?

Ответить
Elry
Elry - 08.01.2022 17:40

AnimationEvent 'StepSound' on animation 'BasicMotions@Walk01 - Backwards' has no receiver! Are you missing a component?

Ответить
Your Majesty
Your Majesty - 29.12.2021 14:02

And than see the same thing in UE4... It's 100 times easier and more professional there...

Ответить
ava obrien
ava obrien - 19.11.2021 17:04

omg thank you!!!!!!!!

Ответить
LAM Cherbaki
LAM Cherbaki - 10.11.2021 20:42

Great tut <3

Ответить
sarah
sarah - 18.10.2021 03:43

Omg, thank you!! Working on an assignment and one little bit wasn't included in our tutorial, your code essentially identical gave me the one line that wasn't provided to us and I kept getting obsolete/deprecated errors on, tried updating to current but that was basically a step backwards. But now... THANK YOU THANK YOU THANK YOU!!!!

(now subscribed 😀)

Ответить
Muhammed Enes Ekinci
Muhammed Enes Ekinci - 28.08.2021 13:04

This way so easy for me, thank you so much.

Ответить
Greg Eckermann
Greg Eckermann - 01.07.2021 02:10

it makes my FPS slow down rapidly I don't know why

Ответить
Juan Camilo
Juan Camilo - 15.05.2021 20:28

Thanks a lot!

Ответить
Mad Marc
Mad Marc - 13.05.2021 23:26

Hi Jason.
I have a question:
The scripts in the download are more intricate then the tutorial. That's cool.
I'm confused, even in the small script in your tutorial appears different in your inspector.
Where is the part that tells the script where your sound files are?
Thankyou so much.
Marc :)

Ответить
Songfugel
Songfugel - 26.04.2021 14:38

Hmm, this seems kinda clever solution, but there does seem to be a lot of work to make it work with complex blend animations.

I just put two colliders to my feet and react to their enter events, then I can easily read the surfaces tag at the same time to switch the sound to match the ground surface.

With this the sound plays every time the feet physically leave and enter the ground

Ответить
Like You
Like You - 20.04.2021 15:26

Finally a solution that works, thanks!

Ответить
Roy [ Random Precision Software ]
Roy [ Random Precision Software ] - 03.04.2021 14:39

how do i use this on a first person style?

Ответить
İlyas Şimşek
İlyas Şimşek - 07.03.2021 17:35

Works like a charm. Thanks.

Ответить
reinaldo rodriguez
reinaldo rodriguez - 16.01.2021 07:09

You are the Man!!! :)

Ответить
Teddy Baker
Teddy Baker - 01.10.2020 22:37

Thank you so much. This is exactly what I was looking for.

Ответить
Dan Iel
Dan Iel - 28.06.2020 01:15

This is a great way of matching sounds to animation.

Ответить
Ben Norton
Ben Norton - 01.06.2020 19:17

I found another solution to the issue with overlapping sounds when using blend trees which is to use the blend weights. The function that the animation event calls can take one parameter, which can be the animation event itself, so you can pass it into the step function and access the blend weights from there to get the audio to only play when it crosses a threshold.
public void Step(AnimationEvent animationEvent)
{
if(animationEvent.animatorClipInfo.weight > 0.5) {
AudioClip clip = GetRandomClip();
audioSource.PlayOneShot(clip);
}
}

Ответить
J P
J P - 26.12.2019 06:19

Thanks! I've used events for sounds before but forgot all about them.

Ответить
Xinyue Yang
Xinyue Yang - 12.12.2019 16:37

What should I put in Audio Source component?

Ответить
LDSR
LDSR - 17.11.2019 05:21

eres mi heroe hermano, mil gracias , tienes sin duda alguna un suscriptor mas

Ответить
בר יערי
בר יערי - 16.11.2019 17:36

if my character got more than 1 animation, how can i choose the animation i want to put the events in?

Ответить
Santiago Manganaro
Santiago Manganaro - 10.10.2019 00:04

GRACIAS CAMPEON!

Ответить
WilliaMusic Chorski
WilliaMusic Chorski - 28.09.2019 08:37

"No harm at all. Worst case, you lose some footstep sounds"


sound designers: :-(

Ответить
Concept Factory
Concept Factory - 27.09.2019 08:07

My animation don't calling event every times, some steps are ignored, why?

Ответить
Oversal
Oversal - 26.09.2019 13:12

The number of times I've been coming back to your unity tutorials is ridiculous, thank you for all your help!

Ответить
Eddy
Eddy - 07.09.2019 07:22

Maybe you know the answer to this, I'm using a blend tree with many animations - For turning while moving, walking, running and so on. How do I get something like this to work with a blend tree? Currently I did this only on the run animation but it doesn't play while turning or walking. If I do multiple, i end up with many sounds playing at once.

Ответить
Istiak Ahmed
Istiak Ahmed - 04.09.2019 00:28

thank you

Ответить
Paula Oliveira
Paula Oliveira - 21.06.2019 23:58

For those ho have a issue with blend animations, here is my solution: i just added a second Audio source, one for each feet (AudiosourceL and AudioSourceR), in the Script i copied the Step Function and rename it as StepL and StepR, finally in Animation Event i'm added a StepL (for left Foot) and a StepR(for right foot), and to prevent the audio to run multiple times, i just added a AudioSource.isPlaying.


something like that:
PS: have some modification to detect a tag from the Gameobject when the player is under it and is diferent from terrain texture, Wood, metal, concrete...
--------------------------------------------------------------------------------------
using UnityEngine;

public class FootSteps : MonoBehaviour
{
[SerializeField]
private AudioClip[] stoneClips;
[SerializeField]
private AudioClip[] mudClips;
[SerializeField]
private AudioClip[] grassClips;
[SerializeField]
private AudioClip[] woodClips;

private float distance = 20f;
public string floorTag;

public AudioSource audioSourceL;
public AudioSource audioSourceR;
private TerrainDetector terrainDetector;

private void Awake()
{
// audioSource1 = this.GetComponent<AudioSource>();
terrainDetector = new TerrainDetector();
}

public void Update()
{
RaycastHit hit;

Ray footstepRay = new Ray(this.transform.position, Vector3.down);

if (Physics.Raycast(footstepRay, out hit, distance))
{
if (hit.collider.tag == "Terrain")
{
floorTag = hit.collider.tag;
}

else if (hit.collider.tag == "Wood")
{
floorTag = hit.collider.tag;
}

}
}

private void StepL()
{
if (!audioSourceL.isPlaying)
{
if (floorTag == "Terrain")
{
AudioClip clip = GetRandomClip();
audioSourceL.PlayOneShot(clip);
}

else
{
AudioClip clip = GetRandomClip2();
audioSourceL.PlayOneShot(clip);
}
}
}

private void StepR()
{
if (!audioSourceR.isPlaying)
{
if (floorTag == "Terrain")
{
AudioClip clip = GetRandomClip();
audioSourceR.PlayOneShot(clip);
}

else
{
AudioClip clip = GetRandomClip2();
audioSourceR.PlayOneShot(clip);
}
}
}

private AudioClip GetRandomClip()
{
int terrainTextureIndex = terrainDetector.GetActiveTerrainTextureIdx(transform.position);

switch (terrainTextureIndex)
{
case 0:
return stoneClips[Random.Range(0, stoneClips.Length)];
case 1:
return mudClips[Random.Range(0, mudClips.Length)];
case 2:
default:
return grassClips[Random.Range(0, grassClips.Length)];
}
}

private AudioClip GetRandomClip2()
{
if (floorTag == "Wood")
{
return woodClips[Random.Range(0, stoneClips.Length)];
}

else
{
return null;
}
}
}

Ответить
Furkan
Furkan - 25.05.2019 18:06

Wow ; thank you so much. You've discovered a very practical method. :)

Ответить
MrNiko
MrNiko - 19.05.2019 23:16

Thank you very much!!! So helpful :)

Ответить
Concept Factory
Concept Factory - 25.04.2019 10:07

Please, made a tutorial distinguishing steps zones, grass, gravel, wood, iron, water...

Ответить
Cleison Rodrigues
Cleison Rodrigues - 16.04.2019 06:50

Thank you very much!
It's work perfect here.

Ответить
sheep
sheep - 08.04.2019 09:21

i love you

Ответить
Ben Affey
Ben Affey - 23.03.2019 11:40

You are the best! Thank you. You are so helpful all the time! Like

Ответить
Daniel Lipman
Daniel Lipman - 25.01.2019 05:10

Maybe it's only me but I think you should explain that after you set each time the right step in the preview window you should click the add event button and it will set automatic the timestamp. I tried to set the timestamp each time on my own and messed it. Maybe you are explain that and I missed this part. Great tutorial it's just it took me some time to understand this timestamp part.

Ответить
Michael Warstler1
Michael Warstler1 - 04.12.2018 01:26

Super helpful and clear, thanks!

Ответить