3RD PERSON CONTROLLER in Unity - FALLING & LANDING

Поделиться
HTML-код
  • Опубликовано: 12 янв 2025

Комментарии • 272

  • @GGodis
    @GGodis 3 года назад +35

    Sebastian. Your 'Physics.SphereCast' is missing the 'maxDistance'. In the Unity's documentation, you can see that the 'layerMask' comes after the 'maxDistance'. You're feeding your 'groundLayer' (LayerMask) (that get's casted to 'int' by the 'LayerMask' operator). In the end your 'groundLayer' value for Unity IS the 'maxDistance'.

    • @GGodis
      @GGodis 3 года назад +3

      @@SebastianGraves I've double checked all available functions/methods in Unity's Physics class, there are no such overrides. The 'layerMask' always comes after the 'maxDistance'. Plus, see the Unity's documentation.

    • @GGodis
      @GGodis 3 года назад +4

      @@SebastianGraves Sorry. I was not aware of the C#4 feature for the 'Named and Optional Arguments' aka 'out of order' default variables. Looks dangerous... It seems that in your case the 'maxDistance' would simply get it's default 'Infinity' value. Thanks for your hard work. Really love your tutorials.

    • @SebastianGraves
      @SebastianGraves  3 года назад +9

      @@GGodis Huh, I just learned something new! Thanks for the bit of information. Glad you enjoy the content my friend :^)

    • @GGodis
      @GGodis 3 года назад +2

      ​@@SebastianGraves I did a bit more reaserch. There IS a problem as I've explained regarding the missing 'maxDistance'! Here is the proof: Your 'groundLayer' mask is using 'Default', as an 'int' it would be equal to '1'. Try and draw a sphere of the SphereCast collision 'hit.point'. Comment out your gravity code and try to move the player character in the Unity editor while in Play mode. You'll notice that the SphereCast would only detect collisions that are in the distance of '1'! Additionally, while in Play mode you can try and change your 'groundLayer' mask in the editor and you will notice how the SphereCast hit.point results will change when the player character is moved by mouse in the editor. So this is not even the case of C#'s 'Named and Optional Arguments', as in this case the 'maxDistance' would be 'Infinity' and your code logic would not work at all. ;) Hope this helps.

    • @SebastianGraves
      @SebastianGraves  3 года назад +6

      ​@@GGodis The layer identification being an int makes sense. I will re-pin the comment, for others to see! Thank you once again for the insight. I probably would not have noticed unless I revisited the series :^)

  • @jaypenter6718
    @jaypenter6718 2 года назад +69

    This is late but others down the line should find this useful I found personally this video needs a few fixes to work as shown in the vid: 1st- physics spherecast should be as follows: if (Physics.SphereCast(rayCastOrigin, 0.2f, Vector3.Down, out hit, 0.5f, groundLayer)
    2nd- on the grounded AND interacting if statement it should be as follows: if (!isGrounded && playerManager.isInteracting)
    3rd- my problem was it would not exit the animation cycle no matter what so I never regained control of my player (ability to move again etc.) to fix this I added one extra line of code to stabilise: underneath inAirTimer=0; and isGrounded=true; add in this short line as follows: playerManager.isInteracting = false; (doesn’t need explaining I’m sure this line explains itself)

    • @edawkingyoutube4004
      @edawkingyoutube4004 2 года назад +8

      Hey bro it seems which you have mentioned is right, however there is one issue that is when starting its keeps on looping in falling animation, so it seems we have to add this line on :
      Void Awake()
      {
      isGounded = true;
      }
      so that the falling animation doesn't loops the player falling when it start.

    • @castlecodersltd
      @castlecodersltd 2 года назад +1

      Jay, thank you for this. It really helped

    • @noblephantasms7250
      @noblephantasms7250 Год назад

      @@edawkingyoutube4004 Which script would this be added to?

    • @dereksullivan1501
      @dereksullivan1501 Год назад +2

      That last line is just what I was looking for.😁

    • @nessap5009
      @nessap5009 10 месяцев назад +1

      Thank youuuuu!🥹

  • @frankkubrick865
    @frankkubrick865 3 года назад +24

    You're a god level teacher and a brilliant programmer Sebastian, thank you so much!!

  • @arbuzxx
    @arbuzxx Год назад +7

    Guys in order to make it instant to switch to landing animation, on the transition from falling to landing uncheck the "Has exit Time", and add the condition "isInteracting" to true

  • @A.P.0000
    @A.P.0000 2 года назад +4

    First of all, great tutorial. Thanks for your amazing work.
    I had a problem with the falling animation and i am seeing many people having a similar problem in the comments. In my case the solution was simply modifying the transition from falling to landing. I unchecked the "has exit time" on this transition, and added "isInteracting" bool as a condition for this transition and set it to "true". This solved the problem.
    However i must give my warning, i am not an expert in unity, so this is just something that worked for me. It might work for you, but there is a possibility that this is not actually a good solution. So take care if you want to apply it.

  • @abraiyan7984
    @abraiyan7984 3 года назад +5

    "Very simple and very straightforward!" Thanks a lot for this series.

  • @imconfused6955
    @imconfused6955 3 года назад +5

    I like how you arent afraid to use headers and stuff to organize your code, so many other tutorials skip over that so its never learned.

  • @yash_solanki
    @yash_solanki 3 года назад +11

    if your land animation play in the air even if player is landed
    then here's the fix --> on your Animation go to "root Transform position Y" and change it from Original To Feet

    • @chez-wren
      @chez-wren 3 года назад

      thanks for the fix man, and what he means is to edit the animation file's import settings not in the animator

    • @TygeTV
      @TygeTV 11 месяцев назад

      @@chez-wren How do i do that?

    • @lildbun1923
      @lildbun1923 10 месяцев назад

      thanks bro

  • @SamuelPollack-f7j
    @SamuelPollack-f7j 6 месяцев назад +1

    to anyone who desires a smoother transition between landing and the locomotion, play with the speed of the landing animation and instead of the return function activating when an input is active, have it activate when the player isnt grounded. I also added my animations to the base layer and connected them to the locomotion, although im not sure how much this impacted the overall smoothing of the animation.

  • @matrunk168
    @matrunk168 3 года назад +3

    To all the people who get stuck in land animation, just check in your base Layer (Animator), and if you have a land animation just delete it.
    You just need one animation on the override section. Because if you got the landing animation in double it will get stuck playing it.
    Hope it will help.

  • @prabhu_rakshit
    @prabhu_rakshit 2 года назад +7

    for anyone whose character is stuck :
    change your raycastheightoffset value to -3 or -4 depending on your character model (if you are not using his model) , the problem for me was that the raycast position was at the center of my character and not at his feet so it was not able to detect the ground at all.

  • @coonslinger333
    @coonslinger333 3 года назад +1

    Honestly your videos are better than Unity's and other paid courses. Please keep them coming! Would love to see more movement based content like jumping and parkour stuff.

  • @ButterDog11
    @ButterDog11 Год назад +5

    I unchecked RootMotion in the animator and it solved like 90% of my problems lol

  • @Rjf32
    @Rjf32 3 года назад +4

    i love these tutorials your better then Brackeys and you explain things so well thank you so much i am new to unity and working on my first real try at a game and these have been tremendously helping me thank you and try to get the next one out fast im hoping its either in jumping or stamina thx for all the help :)

  • @TheGamingzombie1
    @TheGamingzombie1 3 года назад

    So glad you made this video when you did! I've been trying to figure out the whole character model slowly falling thing for a while now!!

  • @anth378
    @anth378 3 года назад

    I'm learning more from your series than the year and a half i spent learning unity, thanks for doing these!

  • @vierkilau
    @vierkilau 3 года назад +1

    Thank you for making this basic version. Really helpful for a newbie like me
    I'm going to be backing the patreon as soon as I get paid at the end of the month

  • @epicdoggames9667
    @epicdoggames9667 3 года назад +1

    Great episode Sebastian!!! Sorry to hear about your hard drive issues. Hoping the next episode comes out soon.

  • @GameOver71910
    @GameOver71910 Год назад +2

    Ran into a couple of problems, I can fall fast now but I've had to push those numbers to the extreme, and I'm still not doing the falling animation just jittering a lot when I lead from the leadge, but when I start my player above the ground it works

  • @PerryThePlato456
    @PerryThePlato456 Год назад +1

    Note for anyone having trouble with the landing or falling try these stuff
    1.make the capsule collider 2 instead of 1.8 if using low poly man
    2. Use play instead of crossfade
    3.on the land animation go to root transform position y and making it from original to feet.
    😊

    • @traynorth83
      @traynorth83 Год назад

      how would i implement play in place of cross fade?

    • @Huzzy267
      @Huzzy267 4 месяца назад

      @@traynorth83have you found this out yet

  • @christopherhaas31
    @christopherhaas31 Год назад +2

    For anyone struggling here, I found it best to add a visualizer of the spherecast by using my player's capsule collider as the source of spherecast radius.
    To do this add two globals at the beginning:
    public Gameobject sphereCastVisual; // You'll need to create Sphere gameObject in scene and pass it in
    CapsuleCollider characterCollider; // Character's collider capsule
    (get the character collider within awake similar to how we get rigidBody `characterCollider = GetComponent();`)
    Then at the start of your HandleFalling():
    RaycastHit hit;
    Vector3 rayCastOrigin = transform.position;
    rayCastOrigin.y += rayCastOffset + characterCollider.radius; // offset with the radius of your capsuleCollider to bring up proper distance
    // Visualize Spherecast Starting Position
    sphereCastVisual.transform.localScale = Vector3.one * 2 * characterCollider.radius; // changing scale to the diameter of sphere
    sphereCastVisual.transform.position = rayCastOrigin;
    My initial thinking of the SphereCast was that it would create a sphere and check if anything is hit within that sphere, but that is not the case. It actually creates a sphere and shoots it along the provided vector for a provided distance and returns true and the hit object if the sphere hits anything along that vector.
    Lastly, I changed SphereCast to this:
    Physics.SphereCast(rayCastOrigin, characterCollider.radius, -transform.up, out hit, maxDistance, groundLayer)
    So in summary, this creates a sphere of radius equivalent to the character capsule collider, centered at the feet of the character (plus the radius of the sphere as set above + given offset), shoots a straight line down (relative to player transform) of distance maxDistance, and outputs the hit object details if anything is hit within the groundLayer.
    ** Note I used -transform.up rather than Vector3.down to allow for character rotation in future, as I plan to have my character run around planets with local gravity **

  • @david100awesome
    @david100awesome 2 года назад +2

    If you are sometimes falling through the floor, make sure on your rigidbody that colision detection is set to continuous!

  • @fawx.1633
    @fawx.1633 3 года назад +2

    Absolutely fantastic series so far. The clear explanations of what you are doing and why is very good. Can not wait for what is coming in the next couple of weeks. Going to start your Dark Souls in Unity series at some point next week.
    What kind of movement will you be covering next? I would personally love to see the following:
    Jumping
    Double Jumping
    Vaulting
    Ledge Climbing/Mantling
    Crouching/Crouch Walking
    Prone
    Obviously not all of these but it would be cool to see how you approach one of these mechanics using the New Input System

  • @xdcretin-_-7363
    @xdcretin-_-7363 3 года назад

    a new underrated champion has risen!

  • @arjunmenon3817
    @arjunmenon3817 3 года назад +4

    finally 3 weeks wait has come to an end🔥🙌

  • @_SF_Media
    @_SF_Media 3 года назад

    As always, a wonderful and clearly spoken tutorial. Looking forward to #7

  • @Zack-pu8xi
    @Zack-pu8xi 3 года назад +2

    For All the people who cant find animations go download them of mixamo there is a lot of free animations to choose from.

  • @ragnaesports5519
    @ragnaesports5519 3 года назад +1

    congratulations for 8k!

  • @benskope
    @benskope Год назад

    Ok, after a few hours of trying to figure it out... My main issue was the animation type of my falling and landing animations. You must remember to put them in humanoid mode in the rig tab otherwise they will not play correctly or even not at all

  • @ZakhiriddinMamadaliev
    @ZakhiriddinMamadaliev Год назад +3

    I had some problems with falling and landing animations not playing at all; could still move while falling and finally my model would fall under ground. Here is what I did:
    - tried every possible solution in the comment section, there is only one suggested fix that worked: if (Physics.SphereCast(rayCastOrigin, 0.2f, -Vector3.up, out hit, maxDistance, groundLayer))
    then adding public float maxDistance = 1;
    - made sure that all spellings are correct (for the bool names)
    - You have to make a transition from falling to landing but DO NOT assign any conditions AND keep the "Has exit time" boxes checked!
    - Your falling animation should be looping and landing should NOT
    - Make sure that your Animator does not have Apply Root Motion box checked
    - Instead of a Box Collider I used mash collider and my model is no longer falling under ground
    These steps helpmed me to resolve the issues

    • @jred7333
      @jred7333 Год назад

      where did you originally use the box collider? also thanks so much for this

    • @ZakhiriddinMamadaliev
      @ZakhiriddinMamadaliev Год назад

      I used mash collider on the ground. Also, if you did everything properly but your character is gliding even when you land (run/walk then jump with W key press) you have to add friction to the ground ( friction 1 works)@@jred7333

  • @SchoolAccount-k3q
    @SchoolAccount-k3q 3 месяца назад +1

    ANYONE WHO IS USING MIXAMO:
    - Make sure to make it a humanoid; Animation->Rig->Animation Type->Humanoid (I don't know if everyone knew this or it was just me)

  • @vinyas0795
    @vinyas0795 3 года назад +4

    Make shooting system tutorials too and i am in love with this series ❤️

  • @doodledoomsday3660
    @doodledoomsday3660 2 года назад +2

    I had to rewrite this code 3 times before I got it working haha, I'm terrible at scripting so maybe that is why.... What I'm trying to say is don't get discouraged if you don't get it the first time and also don't be afraid of starting over.
    Great tutorial as always!

  • @SolReaper
    @SolReaper Год назад +3

    Im not sure why, but I needed to double my transform y value to get the ground detection working, have been following the series to t otherwise, has this been an issue for anyone else?

  • @toasterdoggo7885
    @toasterdoggo7885 3 месяца назад

    gotta love when i make 1 simple typo and get lost for hours on it.

  • @olqb9532
    @olqb9532 3 года назад +1

    What is the benefit of using "-Vector3.up" vs. "Vector3.down" when applying force at 9:35?

    • @yaaannn8126
      @yaaannn8126 3 года назад +1

      same thing

    • @wanchester6626
      @wanchester6626 3 года назад +1

      he is bad idk where he gets his scripts

    • @kingofspades9720
      @kingofspades9720 9 месяцев назад

      @@wanchester6626 He makes his own scripts bro, unlike you he doesnt just copy everything😂

    • @kingofspades9720
      @kingofspades9720 9 месяцев назад

      They act the exact same, my best guess to why he used "-Vector3.up" is because in a lot *most* game engines, they won't have a Vector3.down, because storing that in the Vector3 class as a static variable or similar uses more storage and is useless, so if you want a game engine focused on being lightweight then you would only have Vector3.up, Vector3.right, and Vector3.forward, and even that some engines dont have, instead forcing you to write your own like "new Vector3(0, 1, 0)" which is equivalent to Vector3.up. Unity brands its self on being accessible to anyone, so forcing people to use weird syntax like "-Vector3.up" can be off-putting, so thats why unity decided to include it in their engine, but this video is more of focused on teaching code and stuff rather than "What is the simplest or most efficient way of writing this code". its the same reason why he basically never uses the +=, -=, *=, or /= operators, because some languages like Python, don't have those.

  • @herowars1358
    @herowars1358 9 месяцев назад

    The player ground check only works on the ground, not on any other object, the layers are all the same.

  • @DESTOVIAC
    @DESTOVIAC 3 года назад +10

    Hello,
    I notice this is similar to the Dark Souls tutorial. What separates this from that? Is it a versatility thing or is it more of an update with a generic theme?
    I like this so far; the falling trigger is a little sensitive so the player falls near walls and when running downhill on a rough slope. Any tips to check for those issues? Thanks.

    • @asddsadsad-b8b
      @asddsadsad-b8b Год назад

      did you find a solution?

    • @DESTOVIAC
      @DESTOVIAC Год назад +1

      @@asddsadsad-b8b I did, but it's been so long since I messed with this one that I don't remember exactly what it was. It wasn't perfect though. I believe it had something to do with the if(inAirTimer=0) line, which in my code is if(inAirTimeer>0.1f). Other than that, it may be something to do with the raycast coming from the collider. Either shorten or lengthen the hit distance maybe? Sorry, but it's been awhile on this one. I ended up writing a controller from scratch so I could be sure I fully understood how everything was put together and that only fit what I needed.

    • @asddsadsad-b8b
      @asddsadsad-b8b Год назад

      @@DESTOVIAC ok, thanks!

  • @brennenrocks
    @brennenrocks 3 года назад +23

    FALLING SLOWLY
    Add the "maxDistance" parameter to the SphereCast
    Physics.SphereCast(rayCastOrigin, 0.2f, Vector3.down, out RaycastHit hit, 0.2f, groundLayer)
    STUCK IN FALLING ANIMATION
    Make sure the player IS interacting before landing. The falling animation sets isInteracting to true
    if (!isGrounded && playerManager.isInteracting) {

    • @AntwonKey
      @AntwonKey 3 года назад

      Thanks!!!!

    • @hristoborisov3713
      @hristoborisov3713 3 года назад

      @Namado check your rayCastOffsetHeight, change it to 0 or something that works for you

    • @GGodis
      @GGodis 3 года назад +2

      To get same results as in the video, the 'maxDistance' should be not '0.2f', but '1f'. This is because Sebastian was using the 'groundLayer' mask set only to 'Default'. (When casting 'groundLayer' to 'int' it would result in '1'). Unity's 'SphereCast' took Sebastian's 'groundLayer' for the 'maxDistance'. The real 'layerMask' remained 'DefaultRaycastLayers'.

    • @Typhh
      @Typhh 3 года назад +1

      @@GGodis i was literally going insane trying to understand this. cheers :)

    • @DominoUB
      @DominoUB 2 года назад +1

      Thank you! I couldn't figure it out.
      You can also remove RayCastHit hit and replace it with _
      if (Physics.SphereCast(rayCastOrigin, 0.2f, Vector3.down, out _, 0.5f, groundLayer))

  • @marissaszweda1763
    @marissaszweda1763 Год назад

    Guys, I finally found it out. If you get stuck after you fall give your floor a rigidbody, take off use gravity, and give all freeze positions a tick. It seemed to do it for me

  • @donguyen4801
    @donguyen4801 3 года назад +3

    Can you induce player movement as player go up and down the slope? Thank you for this video

  • @superfunnypranks463
    @superfunnypranks463 3 года назад +3

    Hello guys I need help my falling and landing are not working its like they keep on looping and it never jumps to empty and when it does jump to empty it is for a very short time

    • @SchoolAccount-k3q
      @SchoolAccount-k3q 3 месяца назад

      Did you get a fix for this? Mine keeps randomly changing inAirTimer and playing land and fall but it just gets stuck on the first frames and switches between them.

  • @zaynmalik3981
    @zaynmalik3981 2 месяца назад

    Do you have a link containing the animations of falling and landing?

  • @blakerlee
    @blakerlee Год назад +1

    My character is floating and repeating the falling and landing animations again and again and also my character is going up instead of landing. Please help me...

    • @tedmaster3002
      @tedmaster3002 Год назад

      in the inspector u need to change the RayCastHeightOffSet. try 0.3 or 0.5, maybe it work

  • @peteruelimaa4973
    @peteruelimaa4973 27 дней назад

    Greate series so far, this one is a little rough though.

  • @E-0n-exe
    @E-0n-exe 2 года назад +2

    I am having a strange issue with my project for the falling and landing of a 3rd person controller.
    There doesnt seem to be any immediate issues with my code
    No errors or warnings
    however, my character still floats in the air, the isGrounded bool never gets unchecked
    The animations transitions get stuck and frozen if I force the bool to be false.
    and Im given no warnings or errors as to why
    So i have no idea where to start
    an extra bit of detail i just noticed
    upon starting the scene, the ground variable is active and set to true
    If I walk off a ledge, it stays active and I float
    When I force-ably de-activate isGrounded during play
    this is what happens within an instant and a split seconf
    First : Players gravity kicks in and starts to fall normally
    Second : Ground variable goes from false to true again instantly, even before hitting the ground
    Third : Player animations play until either they hit the ground or they finish playing.
    Forth : The player animations then stay stuck frozen in the end state of the animation
    still no errors from unity or from Visual studio

  • @寝坊月
    @寝坊月 3 года назад +1

    Im not sure why when im grounded and the animation is playing even though isInteracting is TRUE, the handlemovement/rotation script is working. Is return function not working?

  • @RacarCatilla
    @RacarCatilla 3 года назад +3

    Semi-new subscriber here! Love this series, thanks for making it :). I can’t wait for the next one.
    Do you have a set schedule for new vids in this series (I.e. once every 2-3 weeks) or is it just whenever you can get them out?

  • @roberthenderson9175
    @roberthenderson9175 3 года назад +2

    So when I hit play my character immediately starts floating up, then comes down after 30 ft or so and bobs up and down off the ground. in the inspector it looks like its cycling between being grounded and not grounded but i cant find an issue with the code.

    • @josephhanger6380
      @josephhanger6380 3 года назад

      Stuff is happening to me as well. I don't know how adding a downward force can do this, but as I move about, my speed slowing decreases exponentially until I can only turn.

    • @turbulence6
      @turbulence6 2 года назад

      @Sebastian Graves PLEASE PROVIDE A SOLUTION FOR THIS D:

  • @stephanferreira6847
    @stephanferreira6847 3 года назад +5

    When I finished and tested the final thing out, but I ran into two small problems, one (which is not a big deal) the falling and landing animation plays as soon as I start the game, and the other issue is when I fall and then land, the landing animation is slightly delayed and is played a second time after as well

    • @Novecento
      @Novecento 3 года назад +1

      I had the same problem with my landing animation being called twice. I solved by unckecking "Loop time" in my landing animation

    • @noicenoise8718
      @noicenoise8718 3 года назад

      Same here, I noticed the raycast height offset has a factor also. Have you solved this one?

    • @echsengenosse1351
      @echsengenosse1351 3 года назад

      For me checking the box
      Root Transform Position (Y)
      Bake Into Pose
      helped

    • @judzam14
      @judzam14 2 года назад

      Did anyone ever find a solution to this ?

  • @massuritemedia4178
    @massuritemedia4178 Год назад +1

    Is there any way at all to allow movement during the falling/jumping?
    I've tried everything to get freedom of movement while mid-air, but nothing works. I even tried creating separate HandleJumpMovement and HandleJumpRotation methods to call instead of altering the normal movement, but that didn't work either. I really just want to be able to move freely without any frozen rotation or movement, on top of no longer freezing when landing, but I haven't found a way to do so at all and so the movement doesn't feel as reactive or fluent as it could be.

    • @jred7333
      @jred7333 Год назад +1

      Recreate the HandleMovement() in the HandleFallingAndLanding() but change playerRigidbody.velocity = movementVelocity; to playerRigidbody.velocity = new Vector3(movementVelocity.x, playerRigidbody.velocity.y, movementVelocity.z);

    • @lanha3385
      @lanha3385 Год назад

      so do you mean I should paste the handlemovement code into handlefallingandlanding() is it inside if(!isGrounded)?
      @@jred7333

  • @thedragonboy2465
    @thedragonboy2465 3 месяца назад

    my ResetBool isnt interacting with my isInteracting Bool in the animator how do i go about fixing that.

  • @RohanCreation5
    @RohanCreation5 3 года назад +4

    I got an error 01 ( Invalid Layer Index '-1'
    UnityEngine.Animator:CrossFade (string,single) ) 02 ( Animator.GotoState: State could not be found
    UnityEngine.Animator:CrossFade (string,single) ) how can i solve this ?

    • @WaymondDH
      @WaymondDH 3 года назад

      Me Too

    • @WaymondDH
      @WaymondDH 3 года назад +2

      I fixed that I had used the wrong name for my falling animation I used "Falling" but mine is just called "Fall"

    • @RohanCreation5
      @RohanCreation5 3 года назад +1

      @@WaymondDH thankyou sir

    • @johnnyboyt3423
      @johnnyboyt3423 3 года назад +1

      @@WaymondDH Holy crap thanks

  • @Szogun_
    @Szogun_ 4 месяца назад

    when im falling i cant move my player it stand in place and when landed i can walk but why?

  • @anshgulavani4854
    @anshgulavani4854 3 года назад +5

    Using this line --> if(Physics.CheckSphere(rayCastOrigin, 0.2f, groundLayer))
    will give better results than this --> if(Physics.SphereCast(rayCastOrigin, 0.2f, groundLayer, out hit))

    • @epicdoggames9667
      @epicdoggames9667 3 года назад

      Can you explain why?

    • @anshgulavani4854
      @anshgulavani4854 3 года назад

      @@epicdoggames9667 Ya. So CheckSphere uses lesser processor usage than SphereCast which can improve the game performance

    • @epicdoggames9667
      @epicdoggames9667 3 года назад

      @@anshgulavani4854 thanks for the information

    • @GGodis
      @GGodis 3 года назад

      Cool, but it's very likely that you'll need some additional information from the 'hit' class in the future anyway.

  • @coolquincy21
    @coolquincy21 3 года назад +1

    I am having a few issues despite doing the code correctly.
    The first issue is that my character gets stuck in the land animation at the start. The falling animation works normally, however.
    The second issue is that when I do land, I am stuck in the landing animation and I can't move my character.

    • @spiderdlh9905
      @spiderdlh9905 3 года назад

      Mine is doing same if you find how to fix this please let me know

  • @DonDisainer
    @DonDisainer 3 года назад +1

    the one of the series was kind of confusing for me, but this is N E A T

  • @CarlosPipeful
    @CarlosPipeful 3 года назад +2

    I think there was a bug in this video. But maybe I screwed up somewhere.
    can anyone confirm. It wasn't working properly until I changed the if statement
    if(!isGrounded && !playerManager.isInteracting)
    into
    if(!isGrounded && playerManager.isInteracting)
    I could not get it to work other wise.
    the falling animation makes isInteracting = true
    so aslong as we are falling the first if statement will never be true because we are intercting when we are falling. but it is checking for us to not be interacting.

    • @AaronAsherRandall
      @AaronAsherRandall 3 года назад

      Same here. Any idea why this works?

    • @lztverygood
      @lztverygood 3 года назад

      @@AaronAsherRandall i got the same issue, just remove the part "&& player.isInteracting" works for me

    • @lztverygood
      @lztverygood 3 года назад

      if (Physisc.SphereCast...) {
      if (!isGrounded) {

  • @thiagohenrique7452
    @thiagohenrique7452 2 года назад

    Well everything is working great but my land animation never plays.. It seens like the If condition is never meet (I checked the inspector and thats the case).

  • @slavkodem70
    @slavkodem70 Год назад +4

    For now I've found that this version works perfectly:
    private void HandleFallingAndLanding()
    {
    RaycastHit hit;
    Vector3 rayCastOrigin = transform.position;
    rayCastOrigin.y = rayCastOrigin.y + rayCastHeightOffSet;
    if (!isGrounded)
    {
    if (!playerManager.isInteracting)
    {
    animatorManager.PlayTargetAnimation("Falling", true);
    }
    inAirTimer = inAirTimer + Time.deltaTime;
    rb.AddForce(transform.forward * leapingVelocity);
    rb.AddForce(-Vector3.up * fallingVelocity * inAirTimer);
    }
    if (Physics.SphereCast(rayCastOrigin, 0.5f, Vector3.down, out hit, 0.5f, groundLayer))
    {
    if(!isGrounded && playerManager.isInteracting)
    {
    animatorManager.PlayTargetAnimation("Landing", true);
    }
    inAirTimer = 0;
    isGrounded = true;
    playerManager.isInteracting = false;
    }
    else
    {
    isGrounded = false;
    }
    }
    Credit to Jay Penter
    I've also used the landing animation where the player would bend alot and it introduced a problem where the collider would hit the platform and the animation would begin mid-air, then the player would stand normally on the platform, to fix this I went to the animation inspector and checked the "Root Transform Position" -> "Bake Into Pose" which fixed it for me.

    • @mtgk0
      @mtgk0 Год назад

      Thankssss

  • @isolof
    @isolof 10 месяцев назад

    when i run the game my character floats upward for a second, then drops very slowly and when he reaches the ground he does not do the land animation, he just hovers there
    unable to move

  • @strum007
    @strum007 2 года назад +3

    Where can I find these falling and landing animations. The drive link shared a few videos back doesn't have them. Are they behind a paywall or something?
    Being stuck 6 videos into a series does not instill confidence.

  • @Properpeanut
    @Properpeanut 3 года назад

    Awesome episode. A little fiddling around with the raycast length and offset made it all work nicely. One question though. If you would like to run up and down stairs, would you need two racasts at each foot to determine if the collided object is climbable or how would you do it? Right now you have to zig zag to be able to climp stairs.

  • @drakenforge3798
    @drakenforge3798 2 года назад

    There is some kind of bug where even if grounded is set to true, the player will start out in the 'falling idle' animation. If you manually set the bool to true in the inspector window (like he does in the video) it doesn't do that. Also in the physics sphereCast , isInteracting should be set to true.

    • @mixedtrigenito
      @mixedtrigenito 2 года назад

      you need to change the if(!isGrounded && !playerManager.isInteracting) to if(!isGrounded && playerManager.isInteracting)

    • @drakenforge3798
      @drakenforge3798 2 года назад

      @@mixedtrigenito actually i decided that i don't care about this anymore. fuck this.

  • @likuroargend4181
    @likuroargend4181 6 месяцев назад

    My Player always plays the falling animation when going down the stairs, does somebody have a fix for this? allrdy tryed changing the values of the "rayCastMaxDistance", "rayCastSphereRadius" and the "rayCastHeighOffSet", but nothing seems to fix this. Also did all fixes from previous Videos. Maybe somebody can help me :)

  • @funkymushroom
    @funkymushroom 3 года назад +2

    What's the name of the falling animations you got on the unity marketplace?

  • @BMOthePOTATO
    @BMOthePOTATO 9 месяцев назад

    i have appeased the youtube algorithm gods

  • @marmar6496
    @marmar6496 8 месяцев назад

    My character doesn't move vertically when I jump, the animation works, but it doesn't go up, anyone can help?

  • @gamernabilalabadi6240
    @gamernabilalabadi6240 Год назад

    I got Probleme, when my start value if is grounded is true it do not get into the falling animation

  • @LGA_-yd9pn
    @LGA_-yd9pn 7 месяцев назад

    Im having an issue where the feet clip through the plane that im supposed to land on? Im not sure where this issue is coming from

    • @flyingsquirrel1755
      @flyingsquirrel1755 Месяц назад +1

      you can try changing your rigidbody collsiion checking from discrete to continuos, if that doesn't work try messing with the values in the player locomotion script.

  • @MineTechStarship
    @MineTechStarship Месяц назад

    where is the falling animation, now can we find it, its not in google drive

    • @flyingsquirrel1755
      @flyingsquirrel1755 Месяц назад

      im using two animations from mixamo, falling idle and falling to landing, hope this helps

  • @Rjf32
    @Rjf32 3 года назад +2

    it isnt working :( i followed the script and checked everything over no errors it just wont work Help plz

    • @enzo.mp4247
      @enzo.mp4247 3 года назад

      same problem mate did find a solution please, Im totally stuck!

    • @goodcatus2221
      @goodcatus2221 3 года назад

      @@enzo.mp4247 reqork the code. for me also didnt work because i wrote "IsInteracting" instead of "isInteracting". just cant get my falling animation to work.

  • @thorjor1
    @thorjor1 3 года назад

    My fallling animation is finishing after I hit the ground before transitioning to the landing state, so I have this weird full to half second falling animation when I hit the ground before the landing animation plays. "isInteracting" and "isGrounded" are both setting the state immediately like they should, but the falling animation is still trying to finish.

    • @Gathrey
      @Gathrey 3 года назад +1

      click on the transition line in the animator window and make sure that the transition does not have "Has exit time" checked.. if it is checked, the transition will only occur once the animation loop has ended. So unchecking it, will let the transition happen as soon as the condition is true.

    • @lztverygood
      @lztverygood 3 года назад

      or just remove the transition like he said

  • @MrOmenMusic
    @MrOmenMusic Год назад

    why my player falls really slowly? didn't change rigidbody setting and everything's the same as in video

  • @hddbvdcx
    @hddbvdcx Год назад

    Sebastian. I ´have completed this script, but I have a problem. like if I even fall a little bit, it displays the falling and landing animation which I dont want, I only want it do to it when the player fell like 1 meter or more?

    • @flyingsquirrel1755
      @flyingsquirrel1755 Месяц назад

      you can just add an if statement something like, "if (inAirTime > x)"

  • @Aye_Sid
    @Aye_Sid 3 года назад

    Thanks for the video brother...😀👍🏻

  • @huh1884
    @huh1884 2 года назад

    what if I don't have flat land
    how do I prevent my character from playing the animation every time it walks down a slope?

  • @LittleKoneko
    @LittleKoneko 2 года назад

    mine works fine without a landing animation
    you can call isgrounded in the awake method. so the animation doesnt play at the beginning.

  • @kmamashela
    @kmamashela Год назад

    For anybody getting a weird error where the player does land and walks for a bit, but then suddenly enters the falling animation, Make sure that the capsule collider of the player covers their feet. Especially if using a different model. Tweak the collider so that the lowest point is inline with the bottom of the feet.
    This really messed me over for a while lol😂

  • @TheRealHashaam
    @TheRealHashaam 3 года назад +1

    the detection isnt working right my player moves to the landing animation without even touching the ground

    • @woong2335
      @woong2335 3 года назад +2

      Add the condition isInteracting = false to the transition from "Falling" to "Land".

    • @JamEsc196
      @JamEsc196 3 года назад

      Consider lowering the rayCastHeightOffSet to 0.2f instead of 0.5f as instructed in the video. Your collider capsule might be sized more fitting to the avatar than his(i had height of 1.8 instead of 1.7) where it is making it perform landing animation way far up from the ground.

  • @michaelroschmann9327
    @michaelroschmann9327 2 года назад +1

    Can you send me a Link to the Falling and Landing Animations? I cant find something like this in the asset store

  • @vlintonius7141
    @vlintonius7141 Год назад +1

    I finnaly figured it out!!!
    I'll help you guys, i'll write everything that I know of that you can do to fix the falling bug.
    First of al is RootMotion in your animator controller, you need to disable it if your falling movement is really slow or your landing animation sets you off the ground. for the people that do want root motion, here is the newly edited part of the script to reanable RootMotion after the fall.
    Locomotion Script:
    if (!isGrounded)
    {
    if (!playerManager.isInteracting)
    {
    animatorManager.PlayTargetAnimation("Falling", true);
    }
    animator.applyRootMotion = false;
    inAirTimer = inAirTimer + Time.deltaTime;
    playerRigidbody.AddForce(transform.forward * leapingVelocity);
    playerRigidbody.AddForce(Vector3.down * fallingVelocity * inAirTimer);
    }
    if (Physics.SphereCast(rayCastOrigin, 0.2f, Vector3.down, out hit, 1f, groundLayer))
    {
    if (!isGrounded && playerManager.isInteracting)
    {
    animatorManager.PlayTargetAnimation("Land", true);
    }
    if (animator.GetBool("doneLand") == true)
    {
    animator.applyRootMotion = true;
    }
    inAirTimer = 0;
    isGrounded = true;
    animator.SetBool("doneLand", false);
    }
    else
    {
    isGrounded = false;
    }
    and in the resetbool script:
    {
    animator.SetBool("isInteracting", isInteractingStatus);
    animator.SetBool("doneLand", true);
    }
    please note that you need to make a new bool variable Named doneLand in the animator parameters (you can also give it your own name).
    And for those who dont want to reanable RootMotion here is the edited part of the srcipt that still works but if you have a bad animation the you might get pushed of the ground.
    Locomotion Script:
    if (!isGrounded)
    {
    if (!playerManager.isInteracting)
    {
    animatorManager.PlayTargetAnimation("Falling", true);
    }
    inAirTimer = inAirTimer + Time.deltaTime;
    playerRigidbody.AddForce(transform.forward * leapingVelocity);
    playerRigidbody.AddForce(Vector3.down * fallingVelocity * inAirTimer);
    }
    if (Physics.SphereCast(rayCastOrigin, 0.2f, Vector3.down, out hit, 1f, groundLayer))
    {
    if (!isGrounded && playerManager.isInteracting)
    {
    animatorManager.PlayTargetAnimation("Land", true);
    }
    inAirTimer = 0;
    isGrounded = true;
    animator.SetBool("doneLand", false);
    }
    else
    {
    isGrounded = false;
    }
    one further note is to enable the Foot IK on your land animation in the animator controller.
    I hope this helps a few people

  • @RandomSZ
    @RandomSZ 2 года назад

    ive done every line of code, even did a little modifications from people in the comments and all work well, i cant seem to keep my character above the ground the model clips into the floor and stop at the center of it and i tried changing to raycast to -3 and -4 but it starts floating but when its at 0.2 its walkable but clipped into the ground. Anyone know how to fix?

  • @nybro9437
    @nybro9437 Год назад +1

    Im getting this weird bug where my landing animation is overlaping my falling animation, causing it to not fall down but a bit up and then down, repeating itself, anyone knows how to fix this?

    • @lanha3385
      @lanha3385 Год назад

      I am facing the same issue

    • @nilem2007
      @nilem2007 Год назад

      i have the same problem :(

    • @nybro9437
      @nybro9437 Год назад

      I found it was because of the autorig from mixamo, I imported the player model into blender and then I redid the rig and imported it into mixamo again and then used the animations and that fixed the issue in my case

  • @tuskobus2522
    @tuskobus2522 2 года назад

    Everything works but I don't understand why the falling animation doesn't open

  • @NA-pr8lh
    @NA-pr8lh 9 месяцев назад

    My landing animation goes through floor how do I fix that? Do I need a new animation?

    • @NA-pr8lh
      @NA-pr8lh 9 месяцев назад

      Fixed it but now it activates too soon and is done before I hit the ground

  • @kingjoshdes637
    @kingjoshdes637 3 года назад

    hi , i got problem when walking to the slant surface its sliding

  • @mehmetkoman8217
    @mehmetkoman8217 2 года назад +1

    Would you believe me if I said you are my hero?

  • @RaidenHeaven
    @RaidenHeaven 3 года назад

    0:18 no that's what I want, IRL

  • @Warrior9300
    @Warrior9300 3 года назад

    Finally! You are awesome!!! When will you release the new episode? I Just need a rolling action and maybe a Jump, and i'll became a new patreon because your videos are gold!!!

    • @SebastianGraves
      @SebastianGraves  3 года назад

      This weekend! If my PC is back in working order :^)

  • @enclosedabra
    @enclosedabra 7 дней назад

    Hey, thanks so much for making these tutorials! They're the best ones I've seen. I do have a small question. Even though (I think) I have the exact same code, by the end of the tutorial I wasn't able to get the game to recognize when the player is grounded or not. So my character just ends up moving very slowly, like in the start of the video. I was wondering if anyone found a solution to this or not? If I figure out the answer I'll make sure to document it here.

    • @enclosedabra
      @enclosedabra 7 дней назад

      I am also still able to make the character walk while in air, but I'm not sure how to fix it.

  • @rachelwielgopolski0609
    @rachelwielgopolski0609 7 месяцев назад

    Any idea why my character falls like molasses even when I have the falling velocity up to 350?

  • @cosmingugoasa5949
    @cosmingugoasa5949 3 года назад

    isnt the raycast detecting the player capsule collider before the environment colliders ?

    • @kingofspades9720
      @kingofspades9720 9 месяцев назад

      I know this is a late response, but thats why we have the "groundLayer" variable, because the raycast will only detect layers in that layermask

  • @bayefek8047
    @bayefek8047 3 года назад

    Hey man can you make a video about strafe walking animation and its code

  • @troisot1107
    @troisot1107 3 года назад +1

    Could you make first person char controller climb tutorial ?

  • @vrtech473
    @vrtech473 3 года назад

    can you do climbing logic as well?

  • @Hypn0ninjaGaming
    @Hypn0ninjaGaming Год назад

    i wonder if anyone could help please. ive finished the vid but now my character doesnt move. His animation plays but he stays exactly where he is. The error I have is
    Animator.GotoState: State could not be found
    UnityEngine.Animator:CrossFade (string,single) -
    Invalid Layer Index '-1'
    UnityEngine.Animator:CrossFade (string,single) and its pointing to this part of the script: animator.CrossFade(targetAnimation,0.2f); Loving the tutorial but im a bit lost with this issue. Thank you :)

    • @flyingsquirrel1755
      @flyingsquirrel1755 Месяц назад

      your animation in the project is probably named different than the one you're calling

  • @tiagocorsato
    @tiagocorsato 3 года назад

    Sebastian, I followed everything in the tutorial but I keep getting a problem where the land Landing animation only plays when the Falling animation ends. I dont know whats going on.

    • @SebastianGraves
      @SebastianGraves  3 года назад +2

      Make a transition from the falling to the landing animation. Make the condition on it "IsGrounded". So it can only transition if the player is no longer in the air.
      Next uncheck "Has Exit Time" so the transition animation plays instantly. :^)

  • @donbalanzat
    @donbalanzat 3 года назад

    I think I've done all the code right but I'm having an issue. My character falls and lands correctly, but then just kind of bounces in place and I'm unable to move. The "isGrounded" bool blinks true/false and "isInteracting" bool in the animator stays on. Any help appreciated :)

  • @DJKhelb
    @DJKhelb 3 месяца назад

    isInteracting doesn't get checked ever, anyone know what the problem might be?