If you need help with any of the code shown, just visit the "coding-help" channel on my discord server :D Also you can find many more movement tutorials on my channel in the "Tutorials!" playlist - I really hope they help you on your further GameDev journey! And in case you're interested in getting access to my full MOVEMENT LAB, where I combined all of the movement abilities shown in the tutorials and some more, check out the trailer: ➡ MLab Trailer: ua-cam.com/video/9_Q9UxK7VF8/v-deo.html Also, since I know lot's of you are interested in ranged combat as well - I can gladly announce that I'm about to release my RANGED COMBAT LAB as well: 🏹 RcLab Trailer: ua-cam.com/video/j2YplilHjCA/v-deo.html Thanks so much for watching, hope this tutorial has helped you!
For anyone who' might be wondering why the crouch speed is really slow / jittery or barely seems to be moving at all no matter what you set crouchSpeed to, It's not the states or the ground detection. You have to put a frictionless physics material on the ground object or you get the same bug as when moving against a wall with friction and the player "sticks" to it.
@@AreWeLearningYet77 he left out the "else" on the last one for the crouch - see the other comments - it needs to be if.... else if.... else if..... NOT what we got in the vid which is if... else if.... if....
You know, these are the types of tutorials you like to see, straight to the point, easy to follow, but now boringly slow, and explained perfectly. Keep up the good work 👏
For those struggling with very weird movement on slopes and not being able to jump on them, try changing the line "grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.2f, whatIsGround);" to "grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.3f, whatIsGround);" sp change 0.2f to 0.3f. Atleast thats what fixed it for me
Thanks for this! I am realising that this movement is buggy in stairs because if your stairs are set as what is ground, when the character hits the front it will start extra drag so it stops the character for half a second. Anyone found the fix?
Please pin this comment, for those having issues with going down slopes being bumpy please make sure that the series of if statements in the move player method are else if's and not multiple different if statements. Also in the state Handler method please make sure that they are all else if until the last one which is an else because otherwise your code won't work correctly. This is what caused issues in my code and it took me forever to figure it out. Please make sure that these are correct.
For people struggling with the slope with high character velocity, you can add more force to "80f" so you don't get launched in the air, but dont put too much or you'll be stuck on the slope which is worse
@@thazeus1754 go in the script and where you can add force "Vector3.down * 80f" you can get this more high, also normally you can fix it also by verifying missing lines in your code :)
This has seriously been a god send, thank you for making these videos, I've learned so much in a such a short amount of time and it is very easy to adapt into my own project
alternatively, you could use animations for crouching. you can simply create an animation within the Unity dope sheet animator, move the players collider and model down, resize things if needed to prevent clipping, or pose them as well if they are a rigged model. this should resolve any temporary floating in mid air, though you could simple make an if-statement and alternative animation for when the player model is not grounded so that they don't suddenly drop downward. there's always much more easier alternatives, provided you learn about their attributes
You are amazing! I love your voice because it makes everything clearer, you don't miss a word 😎Your tutorials are great! Thanks to you and some further additions, now I can manage an advanced on-ship deck movement!
There will be no need to add downward force on crouch if your player's pivot is at his feet. This also negates the need to know the player's height before raycasting to check for ground. And additionally helps placing units/characters in the scene without needed to adjust their Y position so they don't clip through the ground.
but it can be a real b*ch with all the Rigidbody.Addforce stuff etc gravity goin' on - like center of gravity really helps in Physics in Unity. Could you imagine if you r center of gravity was instead placed at your feet? What a DRAG man
@@TakaShitake-rt8bz You can actually set that manually. And if your rotation is locked anyway, which it is for most character controllers, then the center of gravity doesn't matter at all.
@@MaxIzrin force on crouch is the best way to guarantee you are the "floor" of any low ceiling shaft, duct, tunnel, cave - that's in essence most important especially if you crouch forward and come into a cave that is 3/4 of your height - you stand up - you will clip the ceiling - you need to make sure at all times when in a crouch environment you are at the lowest point of it - to guarantee a raycast up to check ceiling only hits something your full height or lower - anything above is false and you can stand up - and not clip.
@@TakaShitake-rt8bz the issue with adding force down is that u cant do something like crouch jump. if u hold crouch while in air the player gets pushed down constantly
my crouchijng doesnt work, only my croush speed works but not my yscale, i havent done the ray casting so im not sure if taht is the problem. help quick!!!!!!
I have followed your last 3 fps movement and the grenade throwing videos. Thankyou so much the way you explain things it is very easy to understand. Will be following the next vids in the series keep it going!! So much to learn. P.s. Please add movement on stairs currently if I try to climb stair the player gets stuck.
Glad you like my tutorials! :D And I'll probably do something about stair movement sometime soon, but it's definitely going to be one of the most complicated tutorials ^^
These tutorials are great, did have an issue with my crouchSpeed not being used whenever i crouched, after i saw that, i noticed that my movement state wasn't being saved. Just had to set the next if statement to else if in the StateHandler!
Two things: 1. THIS IS AMAZING. I'm going to get everyone I know to watch and subscribe. 2. Thank you comment section for being the answer to my problems!
Great video, I'm really liking these tutorials. One thing: Towards the end when you are accounting for on-slope speed control, instead of adding a new bool flag for jumping from slopes, I actually just re-used the 'canJump' flag instead to keep it simpler. Since 'canJump' is only set to false when the player presses the jump bind, and the Jump() method is called right after, you can use it in the SpeedControl() method to only control the speed on the slope when the player has not yet jumped (so when they are still only the slope). It seems to work all the time for me, but my testing wasn't very long so let me know if I missed something. Also have you thought about making videos about using the new Input System and a Character Controller, especially for a third person controller? Again, thanks for the help!
Glad you liked the tutorial! And sure, if this works feel free to do it this way. Also I recently uploaded a video on third person movement. And thanks for the other ideas, I'll think about them!
if anyone is having issues with the raycast detecting ground that isn't there (ie you're high in the air and still able to jump), go to your mesh collider component, cooking options, and deselect "use fast midphase" was tearing my hair out for days trying to figure out why my very short raycast was still detecting ground despite my character being high in the air, tried this and it immediately fixed that issue. edit: you might need to reimport it as well
This does not work. I am still above 1.0 in the air when able to jump. Unless I check convex, I get message: Non-convex Mesh-Collider with non-kinematic Rigidbody is not longer supported since Unity 5. And with convex checked, I can not move up the slope. I also can not crouch through a tunnel.
I have encountered 4 important problems: 1: If you jump close to a wall, you will sometimes get stuck in it. 2: if you stand in a narrow place, you will get stuck 3: Stairs are your main enemy, because if you stand on the edge, you will be stuck forever 4: if you fall and quickly press the control button, you will accelerate a lot
This is cool if your game is set in a flat world with some slopes, but if you're using terrain or any sort of natural environment then your character will ALWAYS be "on a slope" because the ground isn't perfectly flat, which causes all sorts of issues.
I am not sure why this is not mentioned but the walk speed overrides the crouchspeed since you are still grounded. The statehandler still says walking even though you are crouching. Found the issue: My sprint mode had just Else and not Else if. // Mode - Sprinting else if(grounded && Input.GetKey(sprintKey)) { state = MovementState.sprinting; moveSpeed = sprintSpeed; }
Nice work, though the slope movement and jumping could be even simpler: you're basically disabling gravity saying that won't cause problems, then you say there's a problem and you apply downward motion while walking up... basically adding a weird form of gravity back in. There's a few ways you could handle that. I think the best way would probably be this: while you're on slope, change the direction of gravity to point into the slope. Leave default gravity disabled always, and make your own gravity function that calls in update. In it, so if on slope, then apply force equal to the slope normal time negative gravity amount (-10ish for normal m/s), else apply it down instead. Either apply the force in that gravity function, or have the function return a vector that you use.
sometimes, you can help your script by giving it a little nudge - to make sure everything starts in right place. For instance, to help you might in your void start: state = MovementState.walk; to help give it a frame of reference also, the coding demonstrated in the tutorial for the StateHandler() function is not the best truthfully, you need every other one after the first as "else if" for it work best so in your state handler if... else if... else if... else if... for some reason, Dave gets really sloppy in the second half of the tutorial overall, after being so thorough and diligent with good coding in the first parts
Mess with the Jump fource, cooldown, and air multiplier if you are having issues with choppy jumping. For me Force of 13, cool down of 0.7, and multiplier of 1 work well (this is with gravity set at -30 in project settings)
I recommend where it has the bool for the slope and has != 0 to put like 5 or smthn cause your flat ground wont always be completely flat and you dont want slope physics on flat ground so yea
Bro, this tutorial helped me out so much. Can you make a weapon switching tutorial as well? I want to try and finish my project, but I can't figure out how to make your all in one gun script compatible with other weapon switching scripts on UA-cam. With that said, your content is absolutely brilliant. Keep it up!!
Thanks a lot! Glad I could help you :D I kind of did a weapon switching tutorial already, check it out if you want, but it's a bit specific - only for picking up and dropping weapons, not really storing them in an inventory :D
If anyone has troubles going up slopes, have you noticed that when he is on the slope either walking up or down or simply jumping off, on the bottom right of his screen it shows that his movement state is walking which meant that he placed a layer on his slopes. I don't think he showed his inspector of his slopes being on a default layer but after switching it to whatIsGround, I was able to go up and down the slopes along with jumping off. It was sure a pain not understanding why my character is unable to go up slopes or jumping off. Hope this helps if anyone is watching.
For anyone who is having issues with their player not moving while crouched, it is because of the force being applied the entire time the crouch key is held down. The easiest fix is to just put the AddForce code in a while loop that checks if the player is grounded, and only apply the force when not grounded. //crouch if (Input.GetKey(crouchKey)) { transform.localScale = new Vector3(transform.localScale.x, crouchYScale, transform.localScale.z); while(!isGrounded) rb.AddForce(Vector3.down * 5f, ForceMode.Impulse); }
If anyone is having their crouch not make the state into crouching, under the Statehandler make sure to turn Springing into an Else if, if its set as an if too,
Hello Mr.Dave, I noticed that jump height is slightly inconsistent. First/single jump is normal however if you hold down space and jump multiple times all jumps after the first one are slightly higher. I tested this even on your project in the description and i was having the same issue. I know its barely noticable but when changing the jump force or gravity the difference can be felt quite a bit. I was wondering if there is maybe some way to fix this ? The easiest solution would probably be just to make the player jump once but i like the feature of autojumping. Hope you see this and thank you for all the amazing tutorials :D.
Yes, I noticed that as well. I am going to fix it sometime soon, but so far didn't spend more time on it. Try setting the rididbody y velocity directly, so change the line "rb.velocity = new Vector3(rb.velocity.x, 0f, rb.velocity.z);" to "rb.velocity = new Vector3(rb.velocity.x, someJumpForce, rb.velocity.z);" and delete the AddForce line afterwards. Didn't try this out, but it might work :D
For those who struggle with high velocity on going down the slope check your if else statement. I had "if statement" instead of "if else" on grounded check and because of that you're adding more speed when on slope. Or check other people comments. Everyone here is very helpful if (OnSlope() && !exitingSlope) { rb.AddForce(GetSlopeMoveDirection() * moveSpeed * speedMultiSlope, ForceMode.Force);
The slope handling definitely could have been handled better. In hindsight it was actually really funny to rewatch the video and just witness the amount of band-aids and hotfixes you've got to slap on in order to make the movement work. Instead of turning off the gravity, you could play with the player's friction settings depending on their input values.
Hi, great video! Two things, when I crouch the player isn't able to move, can someone help me with this? Second when the player goes down the slopes it bumps a little. Tks!
in the video, he does if.... else if..... if but it's a mistake you need to do: if.... else if...... else if..... he forgot the last "else" - see the other comments cheers - did you make your slopes.... whatisGround layer, perchance?
I have the problem of joting when walking down slope as well, I can add one which make so that there is downward force when walking down as well, but that will push you down on slope as well…
Hi I have a question. I followed the tutorial and now im stuck at the sprinting part. I wrote everything and my player cant sprint and I dont know what is the issue, I tried to modify the code but no succes. Someone know what could be the issue? Thanks a lot. EDIT: I just saw that what changes is my Rigidbody drag. The problem is I dont know how to solve it EDIT 2: found the error, in the Handle ground part i put moveSpeed instead of GroundDrag.
also in the vid, he forgot you really need in crouching part && grounded on all your get input crouchkey if's - make sure you do - for it to work and in state machine and in any other place always make sure... if... else if... else if.... else if... everywhere - he got real sloppy/lazy on this second half after being so good on the first vid. follow the principles from first vid - and sort comments here by "newest first" to easily see all my helpful tips of advice to fix all issues
for some reason, I still bounce up slopes despite having gravity turned off for slopes and the downward force. It just keeps happening. I downloaded your code and I still cant figure it out. If i remove the 0.3f from the if statement in Onslope(), it does fix the issue, but creates a whole new one as then my character does not stick to slopes at all. Is there another solution im missing? This only occurs going up the slopes and only when im sprinting for some reason. Aditionally, I did make some changes to the state handler, but none of those changes should be effecting this. All I did was add a new state, sliding, and made it only set the state to walking and sprinting if the issprinting boolean in my sliding code is false, so i could increase the max speed of sliding. Thank you for the amazing tutorial. Its insanely helpful and I love how quick these are. Im trying to build a movement shooter myself and these are really helpful to get the basic movement options in. Edit: I was able to figure something out. I dont bounce up slopes anymore. However my character still has a hard time sticking too slopes when going down them at higher speeds.
For people for whom slopes are slippery and weird - Check if you put them into WhatIsGround layer. I forgot to do that and they were very janky, after that immidiately fixed :)
@@TakaShitake-rt8bz my character is keep flying when i climb up on a slope. Also the gravity of player is low too, its falling so slow when i jump. How can i fix those?
@@TheRobber16 did you remember to set your slopes to WhatisGround? you need them to have have "ground" like regular ground! this will solve your problems I think? also at 7:28 of his vid, notice at top of screen freeze frame - you have to remember to temporarily turn gravity off for slopes for it all to work together. do not use character controller. Addforce only works with rigidbody do exactly as his previous tutorial
@@TakaShitake-rt8bz Everything works fine, but the problem is that player is falling so slow, almost floating in the air. Also when you climb up a hill and when the hill ends, player keeps climbing a little bit then falls to ground. I think i can correct this mistake with increasing gravity, but how
if anyone is having trouble with the slope code not triggering even though you are on a slope and the raycast is returning true, increase your ground raycast because the code won't execute properly as it thinks you're in the air
Only improvement I'd make to the current video is the crouching. You can currently uncrouch if you are under something and shouldn't be able to. Easy fix for it is to do a ray cast up instead of down and check if you are colliding with a collider or not. may want to also add a check if the collider is a trigger because sometimes you may be in a bush for example. Don't want to stop crouching behavior because of that haha
If you need help with any of the code shown, just visit the "coding-help" channel on my discord server :D
Also you can find many more movement tutorials on my channel in the "Tutorials!" playlist - I really hope they help you on your further GameDev journey!
And in case you're interested in getting access to my full MOVEMENT LAB, where I combined all of the movement abilities shown in the tutorials and some more, check out the trailer:
➡ MLab Trailer: ua-cam.com/video/9_Q9UxK7VF8/v-deo.html
Also, since I know lot's of you are interested in ranged combat as well - I can gladly announce that I'm about to release my RANGED COMBAT LAB as well:
🏹 RcLab Trailer: ua-cam.com/video/j2YplilHjCA/v-deo.html
Thanks so much for watching, hope this tutorial has helped you!
The crouching speed in the script is being rewritten by the other states,
Yep
For anyone who' might be wondering why the crouch speed is really slow / jittery or barely seems to be moving at all no matter what you set crouchSpeed to, It's not the states or the ground detection. You have to put a frictionless physics material on the ground object or you get the same bug as when moving against a wall with friction and the player "sticks" to it.
@@AreWeLearningYet77 he left out the "else" on the last one for the crouch - see the other comments - it needs to be if.... else if.... else if..... NOT what we got in the vid which is if... else if.... if....
everyone taking the time to read thru the comments - also - make sure folks: you set your slopes to WhatisGround for gawd's sakes!! doh!
You know, these are the types of tutorials you like to see, straight to the point, easy to follow, but now boringly slow, and explained perfectly. Keep up the good work 👏
Thanks a lot!
@@davegamedevelopment Dave. The slope system make my Transform spin. I'm using cube collision. Even if I change to capsule It's still spinning.
@@joelkanna3563 did you freeze rotation in rigidbody?
For those struggling with very weird movement on slopes and not being able to jump on them, try changing the line "grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.2f, whatIsGround);" to "grounded = Physics.Raycast(transform.position, Vector3.down, playerHeight * 0.5f + 0.3f, whatIsGround);" sp change 0.2f to 0.3f. Atleast thats what fixed it for me
Thanks for this! I am realising that this movement is buggy in stairs because if your stairs are set as what is ground, when the character hits the front it will start extra drag so it stops the character for half a second. Anyone found the fix?
@@aquaticchicken maybe change the collider so that it is just a slope, not actual steps, then it will work the same as the other slopes.
will get it. Just don't get burnt out. Whenever you need a break, take one.
Please pin this comment, for those having issues with going down slopes being bumpy please make sure that the series of if statements in the move player method are else if's and not multiple different if statements. Also in the state Handler method please make sure that they are all else if until the last one which is an else because otherwise your code won't work correctly. This is what caused issues in my code and it took me forever to figure it out. Please make sure that these are correct.
Thank u that fixed all my movement realated issues
you're a saint
small but important difference!
oh my god i didn't think that would be the problem tysm
bro, you are the best
For people struggling with the slope with high character velocity, you can add more force to "80f" so you don't get launched in the air, but dont put too much or you'll be stuck on the slope which is worse
what exactly did you change? I have the same problem
@@thazeus1754 go in the script and where you can add force "Vector3.down * 80f" you can get this more high, also normally you can fix it also by verifying missing lines in your code :)
change all the Force.Force's to Force.Impulse's and prepare to laugh your ass off
This has seriously been a god send, thank you for making these videos, I've learned so much in a such a short amount of time and it is very easy to adapt into my own project
Ay nice I have actually added sprinting myself before you made this so I was proud of myself also, what an awesome tutorial man keep it up.
Thanks a lot!
your tutorials are superb! please do more of these, you dive deeper than many of the existing chanels and provide us with great learning opportunities
I liked and saved your every single video. It's so helpful for my summer vacation game projects
Thanks a lot!
0:28 sprinting
2:07 crouching
3:46 handling slopes
Thank you so much! Please keep making these tutorials, they are awesome!!
Glad you like them, I'll keep going!
Hello, tank you very much. I started unity last week and you have helped me a lot.
I have did all of your movements lab tutorial
alternatively, you could use animations for crouching.
you can simply create an animation within the Unity dope sheet animator, move the players collider and model down, resize things if needed to prevent clipping, or pose them as well if they are a rigged model.
this should resolve any temporary floating in mid air, though you could simple make an if-statement and alternative animation for when the player model is not grounded so that they don't suddenly drop downward.
there's always much more easier alternatives, provided you learn about their attributes
The animation way is the way to go I would say for beginners... the way he does it in this video is just so janky
You are amazing! I love your voice because it makes everything clearer, you don't miss a word 😎Your tutorials are great! Thanks to you and some further additions, now I can manage an advanced on-ship deck movement!
Damn bro top tier content, I'm sure you had to visit multiple countries to produce a masterpiece like this
Haha thanks a lot!
There will be no need to add downward force on crouch if your player's pivot is at his feet.
This also negates the need to know the player's height before raycasting to check for ground.
And additionally helps placing units/characters in the scene without needed to adjust their Y position so they don't clip through the ground.
but it can be a real b*ch with all the Rigidbody.Addforce stuff etc gravity goin' on - like center of gravity really helps in Physics in Unity. Could you imagine if you r center of gravity was instead placed at your feet? What a DRAG man
@@TakaShitake-rt8bz You can actually set that manually.
And if your rotation is locked anyway, which it is for most character controllers, then the center of gravity doesn't matter at all.
@@MaxIzrin force on crouch is the best way to guarantee you are the "floor" of any low ceiling shaft, duct, tunnel, cave - that's in essence most important especially if you crouch forward and come into a cave that is 3/4 of your height - you stand up - you will clip the ceiling - you need to make sure at all times when in a crouch environment you are at the lowest point of it - to guarantee a raycast up to check ceiling only hits something your full height or lower - anything above is false and you can stand up - and not clip.
@@TakaShitake-rt8bz the issue with adding force down is that u cant do something like crouch jump. if u hold crouch while in air the player gets pushed down constantly
my crouchijng doesnt work, only my croush speed works but not my yscale, i havent done the ray casting so im not sure if taht is the problem. help quick!!!!!!
I have followed your last 3 fps movement and the grenade throwing videos. Thankyou so much the way you explain things it is very easy to understand. Will be following the next vids in the series keep it going!! So much to learn.
P.s. Please add movement on stairs currently if I try to climb stair the player gets stuck.
Glad you like my tutorials! :D
And I'll probably do something about stair movement sometime soon, but it's definitely going to be one of the most complicated tutorials ^^
@Hawk If you wat to move on stairs make an invisible slope overlapping them. It makes them go smoother than other ways and its easy to do.
@@davegamedevelopment ummmmm this is taking awhile
Watch this: ua-cam.com/video/DrFk5Q_IwG0/v-deo.html
it took me many hours to figure how to do slope movment but your method is easy ,thanks a lot
This Man is OP (Overpowered) 😁💪
I like your Videos 👍
Thanks a lot!
These tutorials are great, did have an issue with my crouchSpeed not being used whenever i crouched, after i saw that, i noticed that my movement state wasn't being saved. Just had to set the next if statement to else if in the StateHandler!
YES - and read my other comments in here for more helpful hints - there were a few oversights in the tutorial as presented cheers
Only comment that solved my issue, appreciate it!
Thanks I wasnt able to figure it out
Two things:
1. THIS IS AMAZING. I'm going to get everyone I know to watch and subscribe.
2. Thank you comment section for being the answer to my problems!
when i typed in soft soft tutorial i did not expect it to be tNice tutorials good thank you so much aaaaaaa
TNice tutorials comnt from you is legendary. Uncomplicated like your video!!!
Well worth my sub + my respect. Thank you so much for finding the path out of tutorial hell for me :D
Bet your soft is absolutely amazing! Never give up
Great video, I'm really liking these tutorials. One thing: Towards the end when you are accounting for on-slope speed control, instead of adding a new bool flag for jumping from slopes, I actually just re-used the 'canJump' flag instead to keep it simpler. Since 'canJump' is only set to false when the player presses the jump bind, and the Jump() method is called right after, you can use it in the SpeedControl() method to only control the speed on the slope when the player has not yet jumped (so when they are still only the slope). It seems to work all the time for me, but my testing wasn't very long so let me know if I missed something. Also have you thought about making videos about using the new Input System and a Character Controller, especially for a third person controller?
Again, thanks for the help!
Glad you liked the tutorial! And sure, if this works feel free to do it this way. Also I recently uploaded a video on third person movement. And thanks for the other ideas, I'll think about them!
After long time
Good to see you 👍
:D
Thanks so much for leaving a link to the script! that helps so much when tutorials do that so I can read through the original when I have errors.
This tutorial has made me realize my typing skills are lacking lol.
Well the typing is sped up to fit the audio, but yes, typing fast is equal to increaing your productivity in coding :D
if anyone is having issues with the raycast detecting ground that isn't there (ie you're high in the air and still able to jump), go to your mesh collider component, cooking options, and deselect "use fast midphase"
was tearing my hair out for days trying to figure out why my very short raycast was still detecting ground despite my character being high in the air, tried this and it immediately fixed that issue.
edit: you might need to reimport it as well
This does not work. I am still above 1.0 in the air when able to jump. Unless I check convex, I get message: Non-convex Mesh-Collider with non-kinematic Rigidbody is not longer supported since Unity 5. And with convex checked, I can not move up the slope. I also can not crouch through a tunnel.
Brackeys Leaves, and Dave Arrives, Boys We Got A New One
Haha thanks!
if you dont want to remove gravity on slopes you can add extra downforce while your y velocity is negative on slopes so that you dont fly off of them
I have encountered 4 important problems:
1: If you jump close to a wall, you will sometimes get stuck in it.
2: if you stand in a narrow place, you will get stuck
3: Stairs are your main enemy, because if you stand on the edge, you will be stuck forever
4: if you fall and quickly press the control button, you will accelerate a lot
we've missed you for so long ❤
:D
Ah I need to add crouching to my game. Nice job! I might take some ideas from your movement code
Thanks :D
I was expecting a flood of among us comments from the thumbnail, glad there wasn't any lol, anyway thanks for this video :)
Haha you know, the game dev community just accepted the default Unity capsule as a player model for first-person games xD
Делаю свой контроллер персонажа и должен сказать, что благодаря твоим гайдам у меня получается сделать контроллер гибким
it's finally ti. i'm ready to learn.
Lol, was just on your channel and then a new video popped up.
Nice :D
This is cool if your game is set in a flat world with some slopes, but if you're using terrain or any sort of natural environment then your character will ALWAYS be "on a slope" because the ground isn't perfectly flat, which causes all sorts of issues.
You're a legend you have helpped me alot :')
Thanks, glad I could help! :D
Very great tutorial! It helped a lot!
I am not sure why this is not mentioned but the walk speed overrides the crouchspeed since you are still grounded.
The statehandler still says walking even though you are crouching.
Found the issue: My sprint mode had just Else and not Else if.
// Mode - Sprinting
else if(grounded && Input.GetKey(sprintKey))
{
state = MovementState.sprinting;
moveSpeed = sprintSpeed;
}
saved me a bunch of time. Thanks a lot
Thanks
Thank you buddy !
Ohh I thought the added force would be the reason, thanks!
Omg thank you!
As I said :D I'm following your tutorials now taking your code :D
Haha go ahead ^^
Nice work, though the slope movement and jumping could be even simpler: you're basically disabling gravity saying that won't cause problems, then you say there's a problem and you apply downward motion while walking up... basically adding a weird form of gravity back in.
There's a few ways you could handle that. I think the best way would probably be this: while you're on slope, change the direction of gravity to point into the slope. Leave default gravity disabled always, and make your own gravity function that calls in update. In it, so if on slope, then apply force equal to the slope normal time negative gravity amount (-10ish for normal m/s), else apply it down instead. Either apply the force in that gravity function, or have the function return a vector that you use.
Thank you so much for making stuff in soft a lot easier to understand.
If you input left shift and MoveSpeed is still equal to WalkSpeed,Put the sprint mode under the walking mode in the StateHandler function
sometimes, you can help your script by giving it a little nudge - to make sure everything starts in right place.
For instance, to help you might in your void start:
state = MovementState.walk;
to help give it a frame of reference
also, the coding demonstrated in the tutorial for the StateHandler() function is not the best
truthfully, you need every other one after the first as "else if" for it work best
so in your state handler
if...
else if...
else if...
else if...
for some reason, Dave gets really sloppy in the second half of the tutorial overall, after being so thorough and diligent with good coding in the first parts
For anyone who cant move when crouched remember to actually write GetKeyDown and not just GetKey
👍❤
thx i couldnt figure it out myself x)
legend
ty
or you need to appreciate he left out the last "else" by accident
instead of
if.... else if..... if
try
if.... else if.... else if...
Mess with the Jump fource, cooldown, and air multiplier if you are having issues with choppy jumping.
For me Force of 13, cool down of 0.7, and multiplier of 1 work well (this is with gravity set at -30 in project settings)
I recommend where it has the bool for the slope and has != 0 to put like 5 or smthn cause your flat ground wont always be completely flat and you dont want slope physics on flat ground so yea
or, oh shit - ya can maybe remember to make sure your slope is whatisGround
great tutorials man
actual good code, no brackeys asset store nonsense, this is just what i was looking for
Bro, this tutorial helped me out so much. Can you make a weapon switching tutorial as well? I want to try and finish my project, but I can't figure out how to make your all in one gun script compatible with other weapon switching scripts on UA-cam. With that said, your content is absolutely brilliant. Keep it up!!
Thanks a lot! Glad I could help you :D
I kind of did a weapon switching tutorial already, check it out if you want, but it's a bit specific - only for picking up and dropping weapons, not really storing them in an inventory :D
have. But, your tutorial was amazing and I have made a semi-decent soft. Thanks!
WOW IT WORKED!!!!! THANKS MAN
Glad I could help!
So informative, thanks a lot!
finished 2 in one sittig already lol got the sub
Great! :D
can you please do a series with character controller i would love to see that
great tutorial!!! please make the sliding/wallrunning one
Thanks - Sliding tutorial is going to be uploaded tomorrow :D
If anyone has troubles going up slopes, have you noticed that when he is on the slope either walking up or down or simply jumping off, on the bottom right of his screen it shows that his movement state is walking which meant that he placed a layer on his slopes. I don't think he showed his inspector of his slopes being on a default layer but after switching it to whatIsGround, I was able to go up and down the slopes along with jumping off. It was sure a pain not understanding why my character is unable to go up slopes or jumping off. Hope this helps if anyone is watching.
You really good at explaining thank you
Brackey's back
most people got sotNice tutorialng from tNice tutorials video. Much love!
when i sprint up a ramp or stairs my character keeps the momentum and usually flies over whatever platform i have at the top
saved me so much time thanks a tonne
It feels like I am learning unity from brad garret with that voice.
Breaking Brack
Great video, thank you ! :)
Glad you like it!
it worked! thank you so much!!
OMG THANKS SO SO MUCH THIS HELPED!!!
For anyone who is having issues with their player not moving while crouched, it is because of the force being applied the entire time the crouch key is held down. The easiest fix is to just put the AddForce code in a while loop that checks if the player is grounded, and only apply the force when not grounded.
//crouch
if (Input.GetKey(crouchKey))
{
transform.localScale = new Vector3(transform.localScale.x, crouchYScale, transform.localScale.z);
while(!isGrounded)
rb.AddForce(Vector3.down * 5f, ForceMode.Impulse);
}
ty cuz ive been having a hard ti getting started.
If anyone is having their crouch not make the state into crouching, under the Statehandler make sure to turn Springing into an Else if, if its set as an if too,
Hello Mr.Dave,
I noticed that jump height is slightly inconsistent. First/single jump is normal however if you hold down space and jump multiple times all jumps after the first one are slightly higher. I tested this even on your project in the description and i was having the same issue. I know its barely noticable but when changing the jump force or gravity the difference can be felt quite a bit. I was wondering if there is maybe some way to fix this ? The easiest solution would probably be just to make the player jump once but i like the feature of autojumping. Hope you see this and thank you for all the amazing tutorials :D.
Yes, I noticed that as well. I am going to fix it sometime soon, but so far didn't spend more time on it.
Try setting the rididbody y velocity directly,
so change the line "rb.velocity = new Vector3(rb.velocity.x, 0f, rb.velocity.z);"
to "rb.velocity = new Vector3(rb.velocity.x, someJumpForce, rb.velocity.z);"
and delete the AddForce line afterwards.
Didn't try this out, but it might work :D
@@davegamedevelopment I've tried it out and it works just fine. Thanks for this ;)
@@sanducosmin7427 No problem, glad it works!
I tried this and i can no longer jump 😭
@@deadlocked85 Still need help ?
For those who struggle with high velocity on going down the slope check your if else statement. I had "if statement" instead of "if else" on grounded check and because of that you're adding more speed when on slope. Or check other people comments. Everyone here is very helpful
if (OnSlope() && !exitingSlope)
{
rb.AddForce(GetSlopeMoveDirection() * moveSpeed * speedMultiSlope, ForceMode.Force);
if(rb.angularVelocity.y > 0)
{
rb.AddForce(Vector3.down * forceDown, ForceMode.Force);
}
}
WAS
if (grounded)
{
rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);
}
NOW
else if (grounded)
{
rb.AddForce(moveDirection.normalized * moveSpeed * 10f, ForceMode.Force);
}
else
{
rb.AddForce(moveDirection.normalized * moveSpeed * 10f * airMultiplier, ForceMode.Force);
}
helped me so much Imma subscribe
Thanks yummy script love it
thank you so so so much your a great person you helped
The slope handling definitely could have been handled better. In hindsight it was actually really funny to rewatch the video and just witness the amount of band-aids and hotfixes you've got to slap on in order to make the movement work.
Instead of turning off the gravity, you could play with the player's friction settings depending on their input values.
This is great, thank you!
works perfectly, thank you
Omg thanks very much ! ✨
someone had said this guy sounds like brackeys and i simply cant think of anything else but facts
Hi, great video!
Two things, when I crouch the player isn't able to move, can someone help me with this?
Second when the player goes down the slopes it bumps a little.
Tks!
in the video, he does if.... else if..... if but it's a mistake you need to do: if.... else if...... else if..... he forgot the last "else" - see the other comments cheers - did you make your slopes.... whatisGround layer, perchance?
Absolute legend. Nice one
I have the problem of joting when walking down slope as well, I can add one which make so that there is downward force when walking down as well, but that will push you down on slope as well…
maybe try something like this
if(OnSlope() && (rb.velocity.x > 0 || rb.velocity.z > 0)
{
//apply downwards force
}
That was great. Thank you.
Hi I have a question. I followed the tutorial and now im stuck at the sprinting part. I wrote everything and my player cant sprint and I dont know what is the issue, I tried to modify the code but no succes. Someone know what could be the issue? Thanks a lot.
EDIT: I just saw that what changes is my Rigidbody drag. The problem is I dont know how to solve it
EDIT 2: found the error, in the Handle ground part i put moveSpeed instead of GroundDrag.
Great tutorial but I have a problem for some reason i my crouch walk is the same speed as my movespeed even if the values are diffrent in unity
Did you ever find the problem here?
You guys still looking for the answer ?
@@Sn3adPlays nope
if... else if... if is in the vid but that's not correct you want if... else if... else if.... he forgot the last "else" see the other comments! :)
also in the vid, he forgot you really need in crouching part && grounded on all your get input crouchkey if's - make sure you do - for it to work and in state machine and in any other place always make sure...
if...
else if...
else if....
else if...
everywhere - he got real sloppy/lazy on this second half after being so good on the first vid. follow the principles from first vid - and sort comments here by "newest first" to easily see all my helpful tips of advice to fix all issues
thank u helped me a lot
for some reason, I still bounce up slopes despite having gravity turned off for slopes and the downward force. It just keeps happening. I downloaded your code and I still cant figure it out. If i remove the 0.3f from the if statement in Onslope(), it does fix the issue, but creates a whole new one as then my character does not stick to slopes at all. Is there another solution im missing? This only occurs going up the slopes and only when im sprinting for some reason.
Aditionally, I did make some changes to the state handler, but none of those changes should be effecting this. All I did was add a new state, sliding, and made it only set the state to walking and sprinting if the issprinting boolean in my sliding code is false, so i could increase the max speed of sliding.
Thank you for the amazing tutorial. Its insanely helpful and I love how quick these are. Im trying to build a movement shooter myself and these are really helpful to get the basic movement options in.
Edit: I was able to figure something out. I dont bounce up slopes anymore. However my character still has a hard time sticking too slopes when going down them at higher speeds.
I have this same problem. Hopefuly there is a solution.
hey is there anyway you can post how you fixed the issue, I'm having the same one
Same issue here
You can use a physic material in your character, and set the friction. Works for me.
Nice video. Do you have a tutorial for walking stairs?
Very helpful..thanks a lot.
You got my sub
Thanks!
Hey nice video man looking for the grappling gun part also!!
Glad you like it!
Could you make one for stairs? Mine seems te get stuck on them. Thank you
For people for whom slopes are slippery and weird - Check if you put them into WhatIsGround layer. I forgot to do that and they were very janky, after that immidiately fixed :)
Oh, you are the best. Thank you very very much
you can maybe try reducing some drag on the slopes too like * dragfactor * 1/2 and stuff like that to help if stuck
@@TakaShitake-rt8bz my character is keep flying when i climb up on a slope. Also the gravity of player is low too, its falling so slow when i jump.
How can i fix those?
@@TheRobber16 did you remember to set your slopes to WhatisGround? you need them to have have "ground" like regular ground! this will solve your problems I think? also at 7:28 of his vid, notice at top of screen freeze frame - you have to remember to temporarily turn gravity off for slopes for it all to work together. do not use character controller. Addforce only works with rigidbody do exactly as his previous tutorial
@@TakaShitake-rt8bz Everything works fine, but the problem is that player is falling so slow, almost floating in the air. Also when you climb up a hill and when the hill ends, player keeps climbing a little bit then falls to ground. I think i can correct this mistake with increasing gravity, but how
if anyone is having trouble with the slope code not triggering even though you are on a slope and the raycast is returning true, increase your ground raycast because the code won't execute properly as it thinks you're in the air
yes - and you can see that - by looking over at your "live" inspector view of the State - if not grounded, while on slope, it will say "Air"
Only improvement I'd make to the current video is the crouching. You can currently uncrouch if you are under something and shouldn't be able to. Easy fix for it is to do a ray cast up instead of down and check if you are colliding with a collider or not. may want to also add a check if the collider is a trigger because sometimes you may be in a bush for example. Don't want to stop crouching behavior because of that haha
Thank u for this ❤❤
for some reason when i try going up a slope i get flung in the air