First Person Controller - Footsteps (EP09) [Unity Tutorial]

First Person Controller - Footsteps (EP09) [Unity Tutorial]

Comp-3 Interactive

2 года назад

28,669 Просмотров

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


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

@BlueVoid476
@BlueVoid476 - 23.11.2023 23:18

One question, when you use footstepAudioSource.PlayOneShot... In the Random.Range part, do you use UnityEngine.Random or System.Random?

Ответить
@InfidelAtWork
@InfidelAtWork - 26.10.2023 18:22

My FP Controller sometimes "loses" steps sounds. I debugged layers using this code:

private void Update()
{
// Set a ray starting point at the player's position (typically at the player's feet).
Vector3 rayOrigin = transform.position;

// Cast a ray downward.
Ray ray = new Ray(rayOrigin, Vector3.down);
RaycastHit hit;

// Define a layer mask to specify which layers you want to check (e.g., Terrain).
int layerMask = LayerMask.GetMask("Terrain");

// Perform the raycast and check if it hits anything on the specified layer.
if (Physics.Raycast(ray, out hit, Mathf.Infinity, layerMask))
{
// Get the name of the layer that was hit.
string layerName = LayerMask.LayerToName(hit.transform.gameObject.layer);

// Print the layer name to the console.
Debug.Log("Player is standing on layer: " + layerName);
}
}

and it shows that player is standing on Default layer all the time

Don't know what is wrong. Any idea?

I tried to use this from comments below, but it did not help:

1. Add 'Player' layer to your player's layer.
2. insert the code below.

int layerMask = (-1) - (1 << LayerMask.NameToLayer("Player")); // Raycasy Everything Except "Player" Layer.
if(Physics.Raycast(playerCamera.transform.position, Vector3.down, out RaycastHit hit, 3, layerMask)){

This did not help also:

int layerMask = ~LayerMask.GetMask("Player");
and i write it on samevoid other way it doesnt work

EDIT:

I tried changing sound files. That helped. It means that one file with sound was making problem. When i used only one (just overwrote all files with first one) problem disappeared.

Ответить
@headhunter531
@headhunter531 - 23.10.2023 21:25

When i type
footStepAudioSource.PlayOneShot(______Clips[Random.Range(0, ______Clips.Length -1)]);

It shows an error under "Range" and says " 'Random' does not contain a definition for 'Range'. "

What am doing wrong? Am i missing any files or something?

Ответить
@brick1488
@brick1488 - 12.10.2023 14:57

im a bit late but when i walk on the surface it only playes once and then dosent play again

Ответить
@dremovremen1764
@dremovremen1764 - 08.07.2023 19:14

There's prolly an important comment about this obvious problem, but I haven't seen any, so:
Mike made a mistake - line 261 should be "characterController.transform.position" instead of "playerCamera<...>". In the correct case the tag-checking ray is coming down out of the character object, not the camera (and thus it has a fixed down-direction, while in case with the camera it's changing depending on where you're looking).

Ответить
@dunderguy
@dunderguy - 02.07.2023 23:02

Thanks it works

Ответить
@michaeldaniel967
@michaeldaniel967 - 18.04.2023 20:43

Love this tutorial series and it has been an absolute life saver to someone like me who is completely new to both Unity and programming - but as a few other people mentioned, this one doesn't cover jump/land sounds. I tried to figure it out on my own, using a combination of things covered in this tutorial and another FPS controller code I have which does have jumping sounds. I ALMOST got it to work, except there is a very annoying delay/feedback on the landing sound effect. I'm just using a generic jump and land sound, not separating the differing surface textures to make it easier on myself for now. I've tried a bunch of variations to try and get rid of it, but it won't go away. 

Below are the code alterations I made. Alterations are //commented for now, until I figure this bug out. Also utilized rows of dots to skip over redundant code bits, rather than copy/pasting the entire thing here.

........................

[Header("Footstep Parameters")]

........................

[SerializeField] private AudioClip[] concreteClips = default;
//[SerializeField] private AudioClip jumpSound = default;
//[SerializeField] private AudioClip landSound = default;
//private bool m_PreviouslyGrounded;
//private float NextStep;
//private float StepCycle;
private float footstepTimer = 0;

........................

private void HandleJump()
{
if (ShouldJump)
{
moveDirection.y = jumpForce;
//PlayJumpSound();
}
//if (!m_PreviouslyGrounded && characterController.isGrounded)
//{
//PlayLandingSound();
//}
//if (characterController.isGrounded && canJump &&m_PreviouslyGrounded)
//m_PreviouslyGrounded = characterController.isGrounded;
}

//private void PlayJumpSound()
//{
//footstepAudioSource.clip = jumpSound;
//footstepAudioSource.Play();
//}

//private void PlayLandingSound()
//{
//footstepAudioSource.clip = landSound;
//footstepAudioSource.Play();
//NextStep = StepCycle + .5f;
//}

Gonna send this to you as an e-mail, too, but thought posting here might get some community answers, also!

Ответить
@blast8ify
@blast8ify - 17.04.2023 19:20

Heya, thanks for your tutorial. I have a problem, when I start tge game, i make one step and stop, but the footstep sound keeps playing

Ответить
@lordkrythic6246
@lordkrythic6246 - 01.04.2023 23:05

Your sound links are broken. I also emailed you with a request. Thank you.

Ответить
@tibbs3545
@tibbs3545 - 12.01.2023 01:25

After the if(footstepTimer <= 0) {
add a
footstepAudioSource.pitch = Random.Range(0.9f, 1.1f);
to have a bit of diversity between the sounds!

Great video btw! Helped alot :)

Ответить
@marka.alvareznieves9213
@marka.alvareznieves9213 - 23.11.2022 21:54

Where can I find this script up to this point? I'm interested in making a video game and I'm working on making a sound while crossing puddles of water and activating a echo location-like sound and vfx that spread around the world map within a radius. If anyone can help me or point me in the right direction it would be much appreciated.

Ответить
@monkeyrobotsinc.9875
@monkeyrobotsinc.9875 - 21.11.2022 04:59

really good WOWwoowOWOWowoWOWOW

Ответить
@Kimarnic
@Kimarnic - 17.11.2022 18:21

WARNING: THE DOWNLOAD FILE IS 9.99$, IF YOU'RE NOT GONNA BUY IT, THEN CLOSE THIS VIDEO
waste of my time

Ответить
@RiverHorse01
@RiverHorse01 - 26.10.2022 21:50

Not working, i just get the default case

Ответить
@shang_psycho7414
@shang_psycho7414 - 16.10.2022 00:09

This worked, thanks!

Ответить
@garnishstudio3567
@garnishstudio3567 - 06.10.2022 07:31

Thanks a lot! That was really helpful. I jumped in on this episode without much coding experience, but was able to troubleshoot my way to a working solution, thanks to this video. Cheers!

Ответить
@SamNBCA
@SamNBCA - 03.10.2022 22:06

Not working for me.

When debug out my raycast I'm detecting the player collider and not the ground.

Any idea what i've missed?

Ответить
@RakoGamesOfficial
@RakoGamesOfficial - 02.09.2022 01:00

pretty cool video BUT,

you're supposed to be using lowerCamelCase for variable names
and UpperCamelCase for method and class naming

Ответить
@arminrad5357
@arminrad5357 - 20.08.2022 02:21

thanks

Ответить
@lindal93
@lindal93 - 19.08.2022 02:47

Thank you for tutorial! Maybe you know how to solve the problem: how to make sure that two identical step sounds are not repeated? I mean, it sounds pretty strange when one sound is repeated several times while walking, it may seem that the player is walking on one foot.

Ответить
@bchshz
@bchshz - 21.07.2022 00:01

that HEY GUYS at the beginning had me feeling like ive been touched without consent 😅

Ответить
@drackofeu3122
@drackofeu3122 - 07.05.2022 22:28

thanks ::D

Ответить
@pacojgomez
@pacojgomez - 24.04.2022 00:42

Hello, I am delighted with your tutorials. Although I have a problem: when the player stops you can hear another step, you can avoid this. Thank you.

Ответить
@stefanwuttig
@stefanwuttig - 18.04.2022 10:13

I have some issues. The sound doesnt play. I have no errors. do i miss something?

Ответить
@bloodybeats4101
@bloodybeats4101 - 01.04.2022 19:17

how would i add a jump effect and a landing sound effect? like play "Blank" sound on jump up, and play "Blank2" sound on landing?

Ответить
@davichalitameneguelli6628
@davichalitameneguelli6628 - 24.03.2022 02:28

Hey! Really great tutorial thank you very much for it! I'm a newbie with Unity although I'm familiar with programming so it's helping me a lot!
I just wanna point two stuff out: first one is that the audio needs to be of a small length (around 1 sec), at first I tried a longer one (around 20 secs) but the audio kept overlapping with the next walking interaction so it wasn't working properly;
the second one is that I'm not sure if I got something wrong but in the line "private float GetCurrentOffset => IsSprinting ? baseStepSpeed * sprintStepMultiplier : baseStepSpeed;" multiplying 0.5 with 1.5 would actually delay the audio between each footstep instead of making it play faster, so I used the divison and the audio played correctly when the character sprints.

Thank you again and keep up with the great work!

Ответить
@yellow2188
@yellow2188 - 02.03.2022 19:28

Great tutorial! Please make a sequel - jumping and landing sounds.

Ответить
@infernogamey374
@infernogamey374 - 01.03.2022 14:25

does anyone know why my footstep sounds keep playing even if i stand still i already ran true my code but i still have no clue

Ответить
@eumystik7703
@eumystik7703 - 25.02.2022 03:33

csn someone please help me, it only does the sounds while im jumping.

Ответить
@infernogamey374
@infernogamey374 - 24.02.2022 18:07

i don't know why but i had 8 diffrent vids and non worked this one worked (even tho i had to improvise lol but it was fun) i was about to give up really now i only have some wierd bug where i hear sound nother sound then a long pauze and again sounds for like 3 or 5 sounds and then again a pauze does anyone know how this is happening?

Ответить
@sborropoly
@sborropoly - 07.02.2022 02:05

I need help pls. why in the line 255 it says that "==" cannot be used for vector2 or vector3? it gives me this message as an error

Ответить
@joshnjoshgaming
@joshnjoshgaming - 28.01.2022 22:25

excellent tutorial

Ответить
@X_Daniel466
@X_Daniel466 - 07.01.2022 06:58

With tags i did not know about the foldout thanks.

Ответить
@flashbacksoft
@flashbacksoft - 26.12.2021 19:17

Hi! Great tutorial. I had a question. I'm having an issue where the floor I'm walking on (I just created a big cube to walk on), which has one of these tags applied, sometimes the footstep sounds play but other times not, depending where on the cube I'm walking. I tried printing out the tag from the raycast and as I thought, sometimes unity displays the name of tag as expected, and other times it says that the object I'm walking on is untagged. Thanks for any advice/help.

EDIT: Figured it out. For anyone having the same problem, print out the layer of the object the Ray hits (in my case it was hitting the player itself), and make a layer mask to only collide with an object on a separate ground layer if that makes sense.

Ответить
@bmcg3712
@bmcg3712 - 12.12.2021 10:35

These videos have been incredibly helpful! Thank you!!
Unfortunately, I've been over and over this one and can't get it to work! Every individual footstep sound plays simultaneously, once, when movement starts, and then doesn't play again. I can't figure out what's going wrong! Can you offer any insight?

Ответить
@CRUMVIII
@CRUMVIII - 07.12.2021 14:37

I literally had no idea you can make folders for tags... Learn something neat everyday.

Ответить
@Wexra
@Wexra - 02.12.2021 19:50

I'm making my first complex video game and this series has helped so much! I'm hoping to get a demo done in the next months for a chance at a scholarship at one of my top choice schools, so thank you for making this series. So glad to see you back!

Ответить
@Restart-Gaming
@Restart-Gaming - 01.12.2021 04:31

Do you have any tutorials on making a first person shooter? I bought a first person pack off unity that come with all the arms guns and animation would like to use them in my game map? hope you can help

Ответить
@gennarocc
@gennarocc - 29.11.2021 21:21

This series has been so incredibly helpful. Thank you!

Ответить
@brynarn
@brynarn - 29.11.2021 19:23

Great video!

Ответить
@fast07hzmc401
@fast07hzmc401 - 28.11.2021 02:45

I have a question but when i try to write
footstepAudioSource.PlayOneShot(metalClips[Random.Range(0, metalClips.Length - 1)]); it says
AudioSource does not contain a definition for "Length" and no accessible extension method "Length" accepting a first argument of type 'AudioSoucre' could not be found (are you missing a using directive of an assembly reference?)
I'm kinda new to Unity so yeah would be nice to get some help (:

Ответить
@user-ru5ny8id3p
@user-ru5ny8id3p - 27.11.2021 19:42

Thank you for your tutorials. Can you please make another one about animations?

Ответить
@frostmusicofficial
@frostmusicofficial - 27.11.2021 17:48

You are AMAZING! I never could understand how footstep audio would be possible, various assets never worked for me, thanks a ton man!

Question though, I use terrain on some various parts of my map, is there any way I could use the raycast to detect the actual material on the part of terrain I'm on to change the audio?

Ответить
@residentsicko
@residentsicko - 27.11.2021 15:58

Awesome video as usual mate.
I hate to be "That Guy" but I have triple checked that everything is the same, usually it is some small thing I've missed.
The sounds won't switch!? I've messed about a bit and from what I can see it is playing the default sound no matter the tag. I think.
I know it's a vague explanation but any idea where I've messed up?

Ответить
@brunodanchev5738
@brunodanchev5738 - 26.11.2021 13:56

You probably already know this but I'll still say it, you're a majestic man, with majestic code and a majestic heart, my question to you is whether you're going to teach us about Enemy A.I. soon? I've found this to be the most difficult of all. Have a fantastic day (if you want to, of course)!

Ответить
@SamuelArmer
@SamuelArmer - 24.11.2021 10:32

after completeing this tutorial i get an error "IndexOutOfRangeException: Index was outside the bounds of the array." before this tutorial I had no problems and was working fine

Ответить
@gabrielwhite9881
@gabrielwhite9881 - 23.11.2021 14:14

Is there also a way to ding out what texture is underneath of the player, to get it work for terrains?

Ответить
@benjaminbriggs8640
@benjaminbriggs8640 - 22.11.2021 00:16

the heckin best yo

Ответить
@xil2331
@xil2331 - 21.11.2021 19:39

Amazing video! Always wanted to know how this was done! Great to have you back!!!

Ответить
@pixelpat5276
@pixelpat5276 - 21.11.2021 13:13

How the hell did you know I needed this video today LMAO

Ответить