Announcement

Collapse
No announcement yet.

Variable Jump Height? Longer key presses yield a higher jump?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Variable Jump Height? Longer key presses yield a higher jump?

    Hey, guys! I'd like to edit the jump mechanics in the Third Person Template such that, when the player holds the jump button down, the character will jump higher. In contrast, I'd like a quick button press to result in a short hop. This would give the player much more control over the character's jumping, making platforming feel more natural.

    Where might I get started with such an endeavor? Since I'm sure there are many other platformer enthusiasts about, I'd be sure to share my method, should I get this working, but I'm unsure of where to get started. Any ideas?

    #2
    Jump on key release, jump velocity based on how long the jump key was held down?

    Basically, here's what I'm going for:

    When the player holds down the jump key, the jump will sort of "charge up" from a minimum jump velocity to a maximum jump velocity. The player will jump when the jump key is released or the maximum jump velocity is reached.
    For my purposes, it will probably be a small amount like 0.0 to 1.0 seconds.

    Where I'm stuck is: I need to figure out how to start counting how much time has passed once I hold down the key; and how to get the elapsed time on key release.

    Comment


      #3
      You can check out jumping mechanics here https://answers.unrealengine.com/que...ng-a-jump.html

      Timers would help with your count issue https://docs.unrealengine.com/latest...nts/index.html

      Comment


        #4
        I'm not trying to charge the jump beforehand and have them jump on release. Consider Super Mario Brothers: A quick tap of the jump button will make Mario jump only slightly, but a longer press will have him jump higher until he reaches the maximum. This charging and releasing system isn't exactly what I was going for, but I suppose it will have to do for now. I'll see what I can do with it.

        In the meanwhile, are there any other methods that someone could suggest?

        Comment


          #5
          I don't know why my question was merged in with this one. They are not the same at all.

          The OP for this thread does not want the jump delayed until the key is released, but rather, the jump should just add more velocity (mid-jump) if the key is held down longer.... Which can be accomplished with the CharacterMovement component included in the Character class.

          So, to the OP:

          In your Character's Construction Script, drag off a node from the Construction node and type "jump hold", under Character, look for "Set Jump Max Hold Time". Then, I would make an editable variable so you can more easily edit this on your Character later.

          Click image for larger version

Name:	WAYeonc.png
Views:	1
Size:	198.6 KB
ID:	1067791

          Now, when you select your Character (top left), you should see your editable variable in the Details panel.

          Click image for larger version

Name:	PUNXpIa.png
Views:	1
Size:	203.8 KB
ID:	1067792

          Over in your PlayerController, you also want to make sure that your only actually calling Jump when the player "Can Jump"; and also make sure to call "Stop Jumping" when you release the key.
          Otherwise, you'll be able to infinitely 'double-jump'... going higher and higher... Which is probably not good.

          Click image for larger version

Name:	pYT0cMP.png
Views:	1
Size:	215.8 KB
ID:	1067793

          I think that's all it takes.

          Comment


            #6
            This works pretty well! Thanks! It took a little tweaking of the gravity and the jump height to get a nice-feeling difference between the short hop and the longer jump!

            Comment


              #7
              I know I'm necroing this thread, but...

              I find that with the MaxJumpHoldTime parameter has a problem. When I release the jump, the character's jump height is a little bit higher than when the jump button is released. Is there a fix to this, because I feel that this kind of takes control away from the player.

              My apologies by the way.

              Comment


                #8
                I can't seem to get this to work... How is the jump input supposed to recognize the variable we created? how are those two things linked? I think I'm missing a key point in those instructions... also would it work if I don't have a player controller but if the input graph is on the player itself?

                Comment


                  #9
                  I know I'm a little late to this party, but the way I solved it was to have the character jump with the max velocity when the key is pressed, and when it's released and we still have positive Z velocity, zero out the Z velocity.

                  So if we hold the jump button in, we will experience the full arc, but if we stop at any point, the jump stops.

                  This may not work in all situations, but it worked pretty well for me

                  Comment


                    #10
                    On low FPS, Jump Max Hold Time has serious problems. Meaning that the character will always jump more on big FPS

                    Comment

                    Working...
                    X