Hello, I would like to know how to control the height of a player’s jumps. For example, if I hold down the jump button, the character will jump at it’s maximum height. However, if I tap the jump button instead of hold it, the character does a tiny jump.
Many games I know have this feature. One notable example is “The End is Nigh” in which you can control the height of your jumps depending on how long the button is held down.
I found one similar topic of somebody asking this, but it wasn’t very helpful to me.
Does anybody know how to accomplish this? Seeing how this was a feature in the original Super Mario Bros, I reckon that this shouldn’t be too hard considering that even the NES was able to support that feature. Thanks in advance.
I think this could be done this way:
- Disable the default controls and manually pick a “jump” key on the keyboard
- Check for the jump key pressed. While it is down increase the “Jump speed” of the platform character
- Check for the jump key released and simulate pressing the jump button.
- When the player is on the floor again set the “Jump speed” to the default value.
Instead of using the key released condition you could also start a timer when the button is pressed and make the player jump automatically after a certain time has passed so that the key needn’t be released in order to jump.
Thanks for your reply.
I tried your solution, but sadly, it doesn’t make a difference. Maybe it is because I have multiple buttons that simulate jumping.
If one of these conditions is true: Simulate pressing Jump Key for Player
*Up key is pressed
*w key is pressed
*Space key is pressed
I have the default controls turned off. I also edited the code to make it so that only the up key jumps and tried it with your suggestion. Nothing changed.
Can you send me a code please? Thanks.
I made one example couple of years ago. It’s not perfect (no timedelta used for example) but here it is:
I think I would do it even more simply way nowadays. But I hope that helps you to figure something out
Thanks for the example mate! It looks very helpful. I copied the code right from the image.
However, when I tested the project and made the player jump, almost hilariously, he took off like a rocket, got stuck on the ceiling, and wouldn’t fall back down. XD
I couldn’t download the example provided because GD5 can’t run the file. Do I need to edit the player to make this work the way I want it to?
The players behavior is:
1500 Acceleration and Deceleration
Cannot grab ledges
Default controls off
600 jump speed
600 max fall speed
150 max speed
60 slope max angle
Thanks in advance
I’ve not tried this, but maybe the way to approach it is to use the usual platformer behaviour to do the smallest jump and then separately check if the ‘jump’ key is still being pressed and if it is, apply an upwards force to the player character. To avoid the player becoming a rocket you would have to build in a limit to this, which might be with a timer check in the conditions of the event that prolongs the jump.
Thank you for the suggestion, but could I please have a code or something?
I tried your suggestion out, and the jump pressure works, but when I hold the jump button, the player falls to the ground slower, but when I release the key, the player falls faster. Also, it plays the falling animation when the jump button is held. Can you please be more specific?
I’ve had a quick play and adding one new event and one action to the falling event seems to work:
This is a modification of the platformer game that comes with GDevelop, so you’ll have to play with the numbers to suit your game.
I regret to inform that your suggestion did not work.
When I added that code, the player would try to jump, but would only be able to bounce 1 pixel off the ground. Even after changing the numbers, the results were not what I was hoping for. I even tried this in the platformer example to see if I was doing something wrong, and when I put in the exact code that you provided, Kenney (The little alien) jumped too high, and I couldn’t control the height of his jumps. Not even with button taps.
Is there another solution? BTW, my player does not have his hitbox as a separate object. The player is his own hitbox if that helps anything.
I forgot to mention I’d also reduced the default jump speed to 400, but regardless I spotted that you could continue to rise higher and higher with rapid pressing of space, so I corrected that. Project is attached.
My project23.zip (146 KB)
I tried this in my project, and it still didn’t work. However, I decided to add the “Simulate Jump Press” to the mix and change some of the numbers a bit, and surprisingly, it worked! The jump pressure function works almost exactly like I imagined it!
I am very grateful for your help mate. Hey, maybe you should make another jump pressure example and post it to Github. Maybe it will be added as an official example!
I would love to see this implemented to the Platform behavior one day, I’m struggling so hard with this at the moment, there’s simply no obvious way of doing it with the tools provided.
I think I can help you out! Here is what I did:
When the key is pressed, add the character to a force of -100 on the Y axis (No x axis), simulate jump key press, and do 600 to gravity (The gravity is a stat on another tab, default 600).
One the key is released, increase gravity to 1500, but only if you’re falling.
Hope this helps mate.
Thank you a lot! I have not tried what you suggested yet, but this is what I did:
It looks less complicated but tweaking the gravity and such may make the desired results harder to achieve.
Here’s how I made it work for my game.I placed a video as well a to show a visual example. You can increase the downward force to shorten the hop more as mine isn’t much shorter than the full jump. But it does work.
I don’t see why not! This could GREATLY benefit players.
Should an example or custom behavoir or something be made as well?
Yes I think most people using G develop to create platformers, would find the jump control techniques useful!
@mtpassd did you change the jump speed on the player?
Yes, quite a while ago actually. However, a recent update added Jump Sustain to the platformer object (Or as I like to call it, Jump Pressure).
I recommend that you just use the Jump Pressure instead. It’s way more convenient and optimal. I mainly asked this before it was added.