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