SLOPE MOVEMENT, SPRINTING & CROUCHING - Unity Tutorial

Поділитися
Вставка
  • Опубліковано 4 лют 2025

КОМЕНТАРІ • 741

  • @davegamedevelopment
    @davegamedevelopment  Рік тому +16

    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!

    • @guillermolmr
      @guillermolmr Рік тому +1

      The crouching speed in the script is being rewritten by the other states,

    • @deadlocked85
      @deadlocked85 Рік тому

      Yep

    • @AreWeLearningYet77
      @AreWeLearningYet77 Рік тому

      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.

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому

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

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому

      everyone taking the time to read thru the comments - also - make sure folks: you set your slopes to WhatisGround for gawd's sakes!! doh!

  • @JW.165
    @JW.165 2 роки тому +122

    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 👏

    • @davegamedevelopment
      @davegamedevelopment  2 роки тому +6

      Thanks a lot!

    • @joelkanna3563
      @joelkanna3563 2 роки тому

      @@davegamedevelopment Dave. The slope system make my Transform spin. I'm using cube collision. Even if I change to capsule It's still spinning.

    • @phnxzy2593
      @phnxzy2593 6 місяців тому

      @@joelkanna3563 did you freeze rotation in rigidbody?

  • @AgentNano
    @AgentNano Рік тому +15

    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

    • @aquaticchicken
      @aquaticchicken 3 місяці тому +1

      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?

    • @dudemanem
      @dudemanem 2 місяці тому

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

  • @jeanpiereramospatricio6954
    @jeanpiereramospatricio6954 2 роки тому +10

    will get it. Just don't get burnt out. Whenever you need a break, take one.

  • @LM-cc7qz
    @LM-cc7qz 2 роки тому +224

    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.

    • @ivania406
      @ivania406 2 роки тому +6

      Thank u that fixed all my movement realated issues

    • @baxifox
      @baxifox 2 роки тому +7

      you're a saint

    • @Skycrafter328
      @Skycrafter328 2 роки тому +4

      small but important difference!

    • @glacial6956
      @glacial6956 2 роки тому +1

      oh my god i didn't think that would be the problem tysm

    • @egorrykunov5757
      @egorrykunov5757 Рік тому

      bro, you are the best

  • @dalidasse9593
    @dalidasse9593 Рік тому +12

    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
      @thazeus1754 Рік тому +1

      what exactly did you change? I have the same problem

    • @dalidasse9593
      @dalidasse9593 Рік тому +2

      @@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 :)

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому +2

      change all the Force.Force's to Force.Impulse's and prepare to laugh your ass off

  • @Chaomaster200
    @Chaomaster200 10 місяців тому

    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

  • @Hyphen3372
    @Hyphen3372 3 роки тому +6

    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.

  • @yairtayb8665
    @yairtayb8665 Рік тому +2

    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

  • @__Rizzler__
    @__Rizzler__ 2 роки тому +4

    I liked and saved your every single video. It's so helpful for my summer vacation game projects

  • @just_gaminlive3402
    @just_gaminlive3402 Рік тому +43

    0:28 sprinting
    2:07 crouching
    3:46 handling slopes

  • @michaelechim2148
    @michaelechim2148 3 роки тому +9

    Thank you so much! Please keep making these tutorials, they are awesome!!

  • @aymeric-devv
    @aymeric-devv 3 місяці тому

    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

  • @fuzziau5669
    @fuzziau5669 2 роки тому +36

    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

    • @notanagger4861
      @notanagger4861 Рік тому +4

      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

  • @FabUni-jy7xj
    @FabUni-jy7xj Рік тому

    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!

  • @johanjaviernavarroticce4632
    @johanjaviernavarroticce4632 2 роки тому +2

    Damn bro top tier content, I'm sure you had to visit multiple countries to produce a masterpiece like this

  • @MaxIzrin
    @MaxIzrin Рік тому +12

    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.

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому +1

      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

    • @MaxIzrin
      @MaxIzrin Рік тому

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

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому +1

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

    • @ramelo07
      @ramelo07 Рік тому +1

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

    • @nightninja1219
      @nightninja1219 10 місяців тому

      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!!!!!!

  • @hawk8566
    @hawk8566 2 роки тому +9

    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.

    • @davegamedevelopment
      @davegamedevelopment  2 роки тому +5

      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 ^^

    • @versenova5531
      @versenova5531 2 роки тому +4

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

    • @ultmatepotato
      @ultmatepotato 2 роки тому

      @@davegamedevelopment ummmmm this is taking awhile

    • @croeusjawad9744
      @croeusjawad9744 2 роки тому

      Watch this: ua-cam.com/video/DrFk5Q_IwG0/v-deo.html

  • @AhmedMohamedHassan-t5b
    @AhmedMohamedHassan-t5b Рік тому

    it took me many hours to figure how to do slope movment but your method is easy ,thanks a lot

  • @theboy6648
    @theboy6648 2 роки тому +2

    This Man is OP (Overpowered) 😁💪
    I like your Videos 👍

  • @driftlume
    @driftlume Рік тому +3

    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!

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому

      YES - and read my other comments in here for more helpful hints - there were a few oversights in the tutorial as presented cheers

    • @chillnook
      @chillnook Рік тому

      Only comment that solved my issue, appreciate it!

    • @zackdasilva3195
      @zackdasilva3195 10 місяців тому

      Thanks I wasnt able to figure it out

  • @sofiaonaga5352
    @sofiaonaga5352 2 роки тому +4

    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!

  • @jerryjayduff2643
    @jerryjayduff2643 2 роки тому

    when i typed in soft soft tutorial i did not expect it to be tNice tutorials good thank you so much aaaaaaa

  • @zuhal5566
    @zuhal5566 2 роки тому

    TNice tutorials comnt from you is legendary. Uncomplicated like your video!!!

  • @aquaphoenix15
    @aquaphoenix15 3 місяці тому

    Well worth my sub + my respect. Thank you so much for finding the path out of tutorial hell for me :D

  • @venkateswaran_muthupandi
    @venkateswaran_muthupandi 2 роки тому +1

    Bet your soft is absolutely amazing! Never give up

  • @tanc4635
    @tanc4635 2 роки тому +14

    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!

    • @davegamedevelopment
      @davegamedevelopment  2 роки тому +3

      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!

  • @ffsensei-q9r
    @ffsensei-q9r 3 роки тому +3

    After long time
    Good to see you 👍

  • @grantmilner8908
    @grantmilner8908 Рік тому

    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.

  • @timothybaldinger261
    @timothybaldinger261 2 роки тому +4

    This tutorial has made me realize my typing skills are lacking lol.

    • @davegamedevelopment
      @davegamedevelopment  2 роки тому +1

      Well the typing is sped up to fit the audio, but yes, typing fast is equal to increaing your productivity in coding :D

  • @irayathecool
    @irayathecool 2 роки тому +2

    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

    • @MatejSunavec
      @MatejSunavec Рік тому

      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.

  • @themooselord9848
    @themooselord9848 2 роки тому +1

    Brackeys Leaves, and Dave Arrives, Boys We Got A New One

  • @simonperry8955
    @simonperry8955 11 місяців тому

    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

  • @issac332
    @issac332 Рік тому +4

    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

  • @xxshartoxx2982
    @xxshartoxx2982 3 роки тому +1

    we've missed you for so long ❤

  • @DevNoob
    @DevNoob 2 роки тому +2

    Ah I need to add crouching to my game. Nice job! I might take some ideas from your movement code

  • @JoshuaDZ
    @JoshuaDZ 2 роки тому +2

    I was expecting a flood of among us comments from the thumbnail, glad there wasn't any lol, anyway thanks for this video :)

    • @davegamedevelopment
      @davegamedevelopment  2 роки тому +1

      Haha you know, the game dev community just accepted the default Unity capsule as a player model for first-person games xD

  • @nikolaytrofficial
    @nikolaytrofficial 25 днів тому

    Делаю свой контроллер персонажа и должен сказать, что благодаря твоим гайдам у меня получается сделать контроллер гибким

  • @amanKumar-xl4fw
    @amanKumar-xl4fw 2 роки тому +1

    it's finally ti. i'm ready to learn.

  • @kraccbaccoriginal
    @kraccbaccoriginal 3 роки тому +3

    Lol, was just on your channel and then a new video popped up.

  • @SeanGauseOfficial
    @SeanGauseOfficial 10 місяців тому +2

    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.

  • @matiasrodrigobaldeonjarro5958
    @matiasrodrigobaldeonjarro5958 2 роки тому +2

    You're a legend you have helpped me alot :')

  • @WillBarker-x1k
    @WillBarker-x1k Рік тому +1

    Very great tutorial! It helped a lot!

  • @Supportik
    @Supportik Рік тому +30

    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;
    }

  • @DevNoob
    @DevNoob 2 роки тому +1

    As I said :D I'm following your tutorials now taking your code :D

  • @Loduwijk
    @Loduwijk Рік тому +1

    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.

  • @mikeylad3834
    @mikeylad3834 2 роки тому

    Thank you so much for making stuff in soft a lot easier to understand.

  • @陈谷歌-g9y
    @陈谷歌-g9y Рік тому +1

    If you input left shift and MoveSpeed is still equal to WalkSpeed,Put the sprint mode under the walking mode in the StateHandler function

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому +3

      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

  • @NHFlol
    @NHFlol 2 роки тому +11

    For anyone who cant move when crouched remember to actually write GetKeyDown and not just GetKey

    • @Sal_Mohn
      @Sal_Mohn 2 роки тому

      👍❤

    • @torbenkramm2725
      @torbenkramm2725 Рік тому

      thx i couldnt figure it out myself x)

    • @dominator1699
      @dominator1699 Рік тому +1

      legend

    • @nando5487
      @nando5487 Рік тому

      ty

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому +1

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

  • @qwertyuiop123-q7f
    @qwertyuiop123-q7f 8 місяців тому

    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)

  • @InvisaPotion
    @InvisaPotion Рік тому +2

    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

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому

      or, oh shit - ya can maybe remember to make sure your slope is whatisGround

  • @hwitweald
    @hwitweald 2 роки тому +1

    great tutorials man
    actual good code, no brackeys asset store nonsense, this is just what i was looking for

  • @sid_.k
    @sid_.k 2 роки тому +1

    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!!

    • @davegamedevelopment
      @davegamedevelopment  2 роки тому +2

      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

  • @zeemidev
    @zeemidev 2 роки тому

    have. But, your tutorial was amazing and I have made a semi-decent soft. Thanks!

  • @Blutengel6661
    @Blutengel6661 2 роки тому +2

    WOW IT WORKED!!!!! THANKS MAN

  • @ivanramos102
    @ivanramos102 2 роки тому +1

    So informative, thanks a lot!

  • @cboyslim5490
    @cboyslim5490 2 роки тому +1

    finished 2 in one sittig already lol got the sub

  • @BlackoutfromMD
    @BlackoutfromMD 2 місяці тому

    can you please do a series with character controller i would love to see that

  • @nikkelob4656
    @nikkelob4656 2 роки тому +2

    great tutorial!!! please make the sliding/wallrunning one

    • @davegamedevelopment
      @davegamedevelopment  2 роки тому +1

      Thanks - Sliding tutorial is going to be uploaded tomorrow :D

  • @Lebas003
    @Lebas003 3 дні тому

    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.

  • @growacc1829
    @growacc1829 2 роки тому

    You really good at explaining thank you

  • @ezioauditore4461
    @ezioauditore4461 Рік тому +1

    Brackey's back

  • @hermes3461
    @hermes3461 2 роки тому

    most people got sotNice tutorialng from tNice tutorials video. Much love!

  • @purble1987
    @purble1987 2 роки тому +7

    when i sprint up a ramp or stairs my character keeps the momentum and usually flies over whatever platform i have at the top

  • @andrellmarrow4642
    @andrellmarrow4642 6 місяців тому

    saved me so much time thanks a tonne

  • @computercrazies
    @computercrazies Рік тому +1

    It feels like I am learning unity from brad garret with that voice.

  • @furkan4657
    @furkan4657 3 роки тому +1

    Great video, thank you ! :)

  • @giuseppedeodato7323
    @giuseppedeodato7323 2 роки тому

    it worked! thank you so much!!

  • @MIO-ym8rx
    @MIO-ym8rx 2 роки тому

    OMG THANKS SO SO MUCH THIS HELPED!!!

  • @enjoilife1128
    @enjoilife1128 Рік тому +1

    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);
    }

  • @brotato9288
    @brotato9288 2 роки тому

    ty cuz ive been having a hard ti getting started.

  • @Toybox_blue
    @Toybox_blue 4 місяці тому

    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,

  • @rado1244
    @rado1244 2 роки тому +11

    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.

    • @davegamedevelopment
      @davegamedevelopment  2 роки тому +13

      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

    • @sanducosmin7427
      @sanducosmin7427 2 роки тому +4

      @@davegamedevelopment I've tried it out and it works just fine. Thanks for this ;)

    • @davegamedevelopment
      @davegamedevelopment  2 роки тому +2

      @@sanducosmin7427 No problem, glad it works!

    • @deadlocked85
      @deadlocked85 Рік тому

      I tried this and i can no longer jump 😭

    • @Sn3adPlays
      @Sn3adPlays Рік тому

      @@deadlocked85 Still need help ?

  • @andreychumakov8952
    @andreychumakov8952 Місяць тому +1

    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);
    }

  • @devsVideo
    @devsVideo 7 місяців тому

    helped me so much Imma subscribe

  • @Deleted328
    @Deleted328 2 роки тому +1

    Thanks yummy script love it

  • @tomshort2558
    @tomshort2558 2 роки тому

    thank you so so so much your a great person you helped

  • @FriedNoodlee
    @FriedNoodlee 11 місяців тому

    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.

  • @khaledzyatahmed1855
    @khaledzyatahmed1855 2 роки тому

    This is great, thank you!

  • @Alihegazy25
    @Alihegazy25 2 роки тому

    works perfectly, thank you

  • @mohamedmahfouz2011
    @mohamedmahfouz2011 2 роки тому

    Omg thanks very much ! ✨

  • @Playeroth
    @Playeroth 2 місяці тому

    someone had said this guy sounds like brackeys and i simply cant think of anything else but facts

  • @SenpaiComet10
    @SenpaiComet10 Рік тому +2

    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!

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому

      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?

  • @carlosjulio8364
    @carlosjulio8364 2 роки тому

    Absolute legend. Nice one

  • @yulovery6398
    @yulovery6398 2 роки тому +1

    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…

    • @adrianluna346
      @adrianluna346 Рік тому

      maybe try something like this
      if(OnSlope() && (rb.velocity.x > 0 || rb.velocity.z > 0)
      {
      //apply downwards force
      }

  • @samarpreet2007
    @samarpreet2007 2 роки тому

    That was great. Thank you.

  • @jonasgonzalez7324
    @jonasgonzalez7324 Місяць тому +1

    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.

  • @z2x128
    @z2x128 2 роки тому +2

    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

    • @Archmage20
      @Archmage20 Рік тому

      Did you ever find the problem here?

    • @Sn3adPlays
      @Sn3adPlays Рік тому

      You guys still looking for the answer ?

    • @z2x128
      @z2x128 Рік тому

      @@Sn3adPlays nope

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому

      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! :)

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому +1

      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

  • @gawczan8218
    @gawczan8218 2 роки тому

    thank u helped me a lot

  • @TheGoldenDragonDev
    @TheGoldenDragonDev 2 роки тому +5

    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.

    • @sflyin6366
      @sflyin6366 2 роки тому

      I have this same problem. Hopefuly there is a solution.

    • @DeBlueGOD
      @DeBlueGOD Рік тому +1

      hey is there anyway you can post how you fixed the issue, I'm having the same one

    • @leonardovalerioxx
      @leonardovalerioxx Рік тому

      Same issue here

    • @leonardovalerioxx
      @leonardovalerioxx Рік тому

      You can use a physic material in your character, and set the friction. Works for me.

  • @loupa6128
    @loupa6128 Рік тому

    Nice video. Do you have a tutorial for walking stairs?

  • @paululanday5420
    @paululanday5420 2 роки тому

    Very helpful..thanks a lot.

  • @TPD_Dev
    @TPD_Dev 2 роки тому +2

    You got my sub

  • @madgaming9165
    @madgaming9165 3 роки тому +1

    Hey nice video man looking for the grappling gun part also!!

  • @heyitsflux1265
    @heyitsflux1265 2 роки тому +1

    Could you make one for stairs? Mine seems te get stuck on them. Thank you

  • @SillySmol
    @SillySmol Рік тому +17

    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 :)

    • @TheRobber16
      @TheRobber16 Рік тому

      Oh, you are the best. Thank you very very much

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому

      you can maybe try reducing some drag on the slopes too like * dragfactor * 1/2 and stuff like that to help if stuck

    • @TheRobber16
      @TheRobber16 Рік тому

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

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому

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

    • @TheRobber16
      @TheRobber16 Рік тому

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

  • @jackdaley9270
    @jackdaley9270 Рік тому +1

    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

    • @TakaShitake-rt8bz
      @TakaShitake-rt8bz Рік тому +1

      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"

  • @genesisr33
    @genesisr33 4 місяці тому

    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

  • @munteanu_555
    @munteanu_555 2 роки тому

    Thank u for this ❤❤

  • @SwivetZip
    @SwivetZip Рік тому +3

    for some reason when i try going up a slope i get flung in the air