Комментарии:
One question, when you use footstepAudioSource.PlayOneShot... In the Random.Range part, do you use UnityEngine.Random or System.Random?
Ответить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.
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?
im a bit late but when i walk on the surface it only playes once and then dosent play again
Ответить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).
Thanks it works
Ответить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!
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
ОтветитьYour sound links are broken. I also emailed you with a request. Thank you.
Ответить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 :)
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.
Ответитьreally good WOWwoowOWOWowoWOWOW
ОтветитьWARNING: THE DOWNLOAD FILE IS 9.99$, IF YOU'RE NOT GONNA BUY IT, THEN CLOSE THIS VIDEO
waste of my time
Not working, i just get the default case
ОтветитьThis worked, thanks!
Ответить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!
Ответить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?
pretty cool video BUT,
you're supposed to be using lowerCamelCase for variable names
and UpperCamelCase for method and class naming
thanks
Ответить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.
Ответитьthat HEY GUYS at the beginning had me feeling like ive been touched without consent 😅
Ответитьthanks ::D
Ответить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.
ОтветитьI have some issues. The sound doesnt play. I have no errors. do i miss something?
Ответить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?
Ответить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!
Great tutorial! Please make a sequel - jumping and landing sounds.
Ответить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
Ответитьcsn someone please help me, it only does the sounds while im jumping.
Ответить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?
Ответить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
Ответитьexcellent tutorial
ОтветитьWith tags i did not know about the foldout thanks.
Ответить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.
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?
I literally had no idea you can make folders for tags... Learn something neat everyday.
Ответить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!
Ответить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
ОтветитьThis series has been so incredibly helpful. Thank you!
ОтветитьGreat video!
Ответить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 (:
Thank you for your tutorials. Can you please make another one about animations?
Ответить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?
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?
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)!
Ответить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
ОтветитьIs there also a way to ding out what texture is underneath of the player, to get it work for terrains?
Ответитьthe heckin best yo
ОтветитьAmazing video! Always wanted to know how this was done! Great to have you back!!!
ОтветитьHow the hell did you know I needed this video today LMAO
Ответить