Making a Character Jump (Unity Tutorial)

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

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

  • @ricardo_original
    @ricardo_original 3 года назад +14

    Great lesson, you explain it very clearly, and you even have work around for a problem that we wouldn't need to address. Congratulations and thank you!

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

      Great to hear this, thanks 😊

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

    Yours so far is the only tutorial I could get the scripts to align with my current code properly with the new input system.
    I just compared the code left on your dotnetfiddle thing but you should post your name on it or something as I actually had a hard time finding the tutorial again after I clicked on the link.
    Deserve a like and follow though as I've gone through hours and hours of tutorials always hitting a wall where everyone seems to hit, and this actually moved me forward with character inputs.
    Thanks so much for the amazing information.

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

    Thank you for this! I recently started using the CharacterController to manage movement and that isGrounded glitch was driving me crazy! You've earned my subscription Ketra; thank you.

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

      Great to hear. Thanks for this comment 😊

  • @Rangwath
    @Rangwath 2 года назад +9

    Really love your lessons, thanks a lot for them. I just had more problems with the ySpeed issue. I'm using different character and initialy had to make it -1 in order to make it stop moving all the time. When I added the idle animation, it broke completely and started moving again all the time. I did some googling and found out a solution that works for me so far, I had to change "Min Move Distance" in "Character Controller" to 0 and this solves the issue for me, can even have the ySpeed = 0 now. Hope this won't cause any new issues thought.

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

      Thanks for sharing your solution. Changing the Min Move Distance to zero will be fine in most scenarios. This is taken from the Unity documentation
      "If the character tries to move less than this distance, it will not move at all. This can be used to reduce jitter. In most situations this value should be left at 0."
      We're planning to do a refresh of these tutorials at some point so will probably change to this solution at that point 😊

    • @katerinahadjipavlou1946
      @katerinahadjipavlou1946 5 месяцев назад

      You are a lifesaver!

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

    This is a good Tutorial series, got stuck for a bit because the Lightbulb wasn't appearing for me.

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

    Great video, still helped me today.

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

    Best videos, thank you !!
    CharacterController Component > Min Move Distance = 0

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

      Thanks for this comment 😊

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

    Amazing video. Your voice is really nice and easy to understand, plus you cover way more than I expected (aka stuff I'd need to spend time googling otherwise). Well done, thank you for this :)

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

      Great, thanks for this comment 😊

  • @qsquid3797
    @qsquid3797 2 года назад +5

    I don't know why but for the ySpeed I had to do -1f for it to work

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

    Man what a good and solid tutorial, thank you so much

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

      Great to hear. Thanks for this comment 😊

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

    that's nice lesson! Thanks to your lesson , I can work very quickly

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

      Glad it was useful 😊

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

    Excellent tutorial, short and well explained. Did you considered calculate the Y velocity based on a desired jump height? I think is also important to know how height are character will get.
    In that scenario is used the formula
    Y VELOCITY = square root ( JUMP HEIGHT * -2 * GRAVITY )

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

      Thanks for the suggestion. We're working on an animated jump tutorial at the moment so we'll probably look to incorporate the jump height into that 😊

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

    If people are still have issues with the jump work around, try setting the "Min Move Distance" to zero.

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

      Thanks for this. Good tip 😊

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

      What min move distance? i dont see that anywhere in the script.

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

    great understanding

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

    Hey! This is a brilliant video but I just would like to ask how do you change the gravity

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

      Hi, thanks for this. To change the gravity you can change it in Edit->Project Settings->Physics. Or you could add a gravity multiplier field in the script. Something like
      [SerializeField]
      private float gravityMultiplier;
      ...
      Physics.gravity * gravityMultiplier
      ...
      That way you can change the gravity multiplier in the Inspector for the character without affecting the gravity of other objects.
      Hope that helps 😊

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

    Hi nice tutorial. I would suggest to have a change to have a option to set player's gravity independently rather than changing phyics.gravity which will affect all other phyics objects.

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

      Thanks. Yes, you're right. Having a gravity parameter would be useful if you wanted the character to fall at a different rate.

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

    The main issue I've found with CharacterController's ground-detection is that it often doesn't work unless you're on totally-level terrain. Any chance you can make a tutorial to address that?

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

    Wow! Great! Thank you for this AMAZING tutorial, perfect for the begginers :). Now I understend more!

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

      Thanks for this great comment 😊

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

    Worked perfectly!

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

    Amazing tutorial! One question: How do I make this work on a mobile phone with Input Get Touch? I tried to add the touch phase but I cannot jump and move the player, it only moves at a slow speed.

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

    Feeling kind stupid but I can't find what I missed, the character ySpeed still keeps fluctuating while standing still and when moving its stable

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

      Hi, you could try changing the Min Move Distance on the Character Controller to zero in the Inspector. Hopefully this will stop the fluctuating speed 😊

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

      @@KetraGames Got same issue, your solution works perfectly well. Thanks and keep going this that great job !

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

    Thank you!

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

    Any tip on how I can get the quick action or lightbulb to pop up? I can't introduce a local variable because I don't see either one of those there to let me do it. Any help would be greatly aprpreciated.

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

      Hi, what code editor are you using? The lightbulb should be there in Visual Studio 2019.
      If you can't get it to work, you can still make the changes manually to continue with the tutorial - it will just take a little longer 😊

  • @番長ほむら
    @番長ほむら 2 года назад +1

    Hello! , is the issue about the isGrounded flag and Step offset obsolete with the newer versions of unity?
    I dont seem to run into the same issues that you have had in this video, if anything its working fine.

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

      Hi, it may be that these issues are now fixed. I'll have to go back and check. Thanks for raising 😊

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

      @@KetraGames I think it's fixed now. I'm using 2021.3.6f1 and when I set the ySpeed to 0f it doesn't fluctuate. If I have it at 0.5f my player bounces up and down, slightly, when it's on the ground

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

    got it too work. for some reason my character doesnt want to jump when going diagnollly.
    when i hold either left+down or up+right, he can jump.
    when i hold either left+up or right+down, he cant jump.
    for now ill leave this aside since i can jump then move diagnolly. any possible reason why this might happen?

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

    how to controll the gravity?, cause i think when the character is jump, the jump is too long in the air, so it's like floating. would you help me

    • @KetraGames
      @KetraGames  2 года назад +4

      Hi, there are two ways you could do this.
      First you could increase the gravity in the physics settings. Editor -> Project Settings -> Physics
      Alternatively, you could add a gravity multiplier in the script. So where we apply the gravity would look something like this
      ySpeed += Physics.gravity.y * gravityMultiplier * Time.deltaTime;
      Then you could set the gravityMultiplier to 1.5 for example to increase the gravity applied.
      Hope that helps 😊

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

      @@KetraGames OOOOhhhhh i see... thanks for your explanation it helped me a lot

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

      @@KetraGames While your suggestion is good, why not just do something like
      (start of script)
      public float gravity = ;
      (gravity logic)
      ySpeed += gravity * Time.deltaTime;
      Is there a reason to use Unity's prebuilt gravity? Maybe NPCs are using rigidbodies, so it's easier to adjust their gravity later on without having to then go back to adjust the player's multiplier.
      Am I just pointing out useless solutions, or is there a reason to do it your way that I'm missing?

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

      @@washurpaws Hi, either way would work, but using the Unity gravity value is a useful global setting that can be used so that all objects in the game are using the same value for gravity. Having a multiplier then allows different objects to fall faster or slower than this value as desired

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

    thank you :D

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

    my character still jumps continuously if i press the space bar. The isGrounded doesnt seem to be working. Am i right in thinking isGrounded isnt set as private bool

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

    does this jump code work with rigidbody character controllers?
    for some reason the ySpeed value does not stop decreasing and my character doesnt touch the ground to trigger the isGrounded bool

  • @nikolas276
    @nikolas276 7 месяцев назад +1

    a good tutorial video, but I'm still tormented by the question of how to make a character fall faster than he gains height

    • @Hoptronics
      @Hoptronics 5 месяцев назад

      I think Iheartgamedev has a video about recreating the Mario jump with animation curves I think.

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

    THANKS A LOT!

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

    ty

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

    Is this tutorials works with a PS5 controller? I’m a beginner and thanks.

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

      Hi, yes this should work with any controller.

  • @knightsvswarriors-v3i
    @knightsvswarriors-v3i 2 года назад +1

    2:23 what if I don't have a light bulb? please help me thanks

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

      Hi, the lightbulb helps you refactor code quickly but if you don't have it you can type the changes manually and get the same result. Hope that helps 😊

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

    Can you tell, how to use jump with character contorll if button is UI based? not keyboard based?

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

      Hi, what you could do is replace the key check with a check on a boolean field. So instead of
      if (Input.GetButtonDown("Jump"))
      {...}
      you could do
      if (jumpButtonPressed)
      {
      ...
      jumpButtonPressed = false;
      }
      You would then need to wire up the button click event to a method that sets this field to true.
      We're planning to do some tutorials on mobile controls in the future but hope this helps in the meantime.

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

    My hero!

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

    How about touch screen input, like going ball game, can u do a tutotrial about the mecanism used(going ball),thx

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

      Thanks for the suggestion. We'll definitely be covering mobile input in future videos

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

      @@KetraGames i hope u will make it as soon as possible, thx for ur great content.

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

    do these tutorials still translate if use a rigid body for my player?

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

      Hi, they won't exactly translate but there will be lessons you can learn and apply when using a rigidbody

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

    Will you do a tutorial to prevent air movements while jumping ?

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

      Thanks for the suggestion. We'll add it to the list of future videos 😊

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

      Good to know 🙂

  • @StarbornVR
    @StarbornVR 5 месяцев назад

    For some reason it only jumps when I move

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

    That's a lovely accent you have there, New Jersey?

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

      Thanks! I'm in the UK 😊

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

    If I want to add force to the Y axis of an object ignoring the environment Y axis , Because the object mute flip and I don't want to push it it from the back. what should I write?

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

      Hi, sorry I don't fully understand the question. If you are adding force to a Rigidbody and you don't want it to flip then you can lock the rotation on any axis. Hope that helps

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

    My character is shaking uncontrollably when i click play, can someone help?

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

    Hey, I've been wanting to create an auto-jump mechanic like the one from Ocarina of time, I've watched tons of movement/ jump tutorials, searched on forums and haven't found anything close to it, could you make a tutorial on this? I'm a newbie and your videos have been really helpful, thanks.

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

      Hi, that sounds like an interesting challenge. We'll add it to the list of future videos.
      I think the way that you would go about this would be to cast a Ray down toward the ground just ahead of your character. If you detect that there is no longer any ground ahead of the character, then trigger the jump.

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

    How do I specify which layer is the ground layer? At this point my character jumps on everything and the .isGrounded return true eachtime.

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

      Hi, you could use the OnControllerColliderHit method to get more detail on what the character has collided with. Then you could check if it's in the ground layer to enable the jump.
      docs.unity3d.com/ScriptReference/ControllerColliderHit.html

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

    Character can only jump when moving else jump is not working at all. By increasing ySpeed it's working.

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

    Why does the character shift a little when the program starts? I noticed that the little red alien goes from 0 for Y to -0.0199 and my own test with a cube goes from 0 to 0.0800. Is there a way for it not to do that?

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

      Hi, you could try repositioning the CharacterController slightly so that it starts off on the ground

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

    for some reason my character just falls through the floor. can anyone help me with this problem?

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

      Hi, have you got a collider component on the floor?

  • @Zainkhan-tk7kt
    @Zainkhan-tk7kt 2 года назад

    Can you move in mid air when you jump

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

      Hi. Yes, you can move in the air 😊

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

    Upon finishing code at 3:00 I can no longer move my character at all, much less jump

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

      Sorry to hear you're having issues. Have you tried copying the code from here to see if that helps - dotnetfiddle.net/0GDAm3

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

    Please also tell how can we add jump with UI button as the game can be for mobile.

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

      Hi, what you could do is replace the key check with a check on a boolean field. So instead of
      if (Input.GetButtonDown("Jump"))
      {...}
      you could do
      if (jumpButtonPressed)
      {
      ...
      jumpButtonPressed = false;
      }
      You would then need to wire up the button click event to a method that sets this field to true.
      We're planning to do some tutorials on mobile controls in the future but hope this helps in the meantime.

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

    for some reason when i jump the player gets stuck in the air for a second then goes back down. It only happens when the player isnt moving its good when im moving

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

      Hi, sometimes the jump can feel a bit floaty using the default gravity value. Try replacing Physics.gravity with a higher value and see if that helps

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

    thanks

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

    Hello please help me.. i followed every step and i am getting issue that my player is getting back to ground very slower like its get back on ground in slow motion how can i fix this please help ...

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

      Hi, it sounds like the gravitational acceleration isn't working properly. Check the line where you add the gravity and check you have it like this
      ySpeed += Physics.gravity.y * Time.deltaTime;
      You can also find the complete script at dotnetfiddle.net/0GDAm3. Hope that helps

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

      @@KetraGames thank you so much ❤️

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

    Nice trick setting step offset to 0

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

    how do we edit the script to add a double jump?

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

      I'm not the original creator of the video, but how I would do it is maybe have a second variable for "has the player doublejumped"? If the player presses the jump button and is grounded, it does the ground logic, but if they are not grounded, Unity will see if the doublejump boolean is true or false. If it allows doublejumping, it does the jump logic again, and marks the doublejump as true. When you're grounded, the doublejump allowed flag is set to true for the next time you need to jump.

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

    my character movement is very laggy for some reason

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

      Hi, not sure why that would be. Do you mean it doesn't respond to input quickly enough?

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

      Wait it's OK the order of the script was wrong so sorry

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

    it is probably good in a series but it is confusing for someone who is just tying to learn how to code a jump correctly.

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

    I dunno why but my character just goes down even when there is a floor;

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

      Hi, does your ground have a collider attached? If so, check that it isn't set as a Trigger.

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

    3:13

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

    sorry but not good for me code working but ingering in my movement

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

    You ia single?

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

    bad tutorial dont expect me to ruin my previously made movement physics just to suit yours

    • @KetraGames
      @KetraGames  3 года назад +8

      Sorry you didn't find this tutorial helpful. There are always multiple ways to solve a problem in software development so you can take concepts covered in the video and adapt them however you like.

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

      Ahahah that's so rude and you clearly don't know programming and are just looking to copy tutorials

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

      💀💀💀