I need help with creating a different type of jump

yadah

  • Posts: 48
So here is what I have so far


I am trying to create a situation to where you have a jump similar to Mario in Super Mario Brothers. The problem is in this code that I have if the user holds it down the player will basically fly as it continually adds force. Any suggestions to make this more like the SMB jump style?

« Last Edit: October 17, 2014, 06:25:28 am by yadah »

UnrealCanine

  • Posts: 244
What I would do is thus;

Make a 'canjump' boolean and set it to true upon hitting the ground, and false when up is released

Alter your code so the player can only jump if canjump is true

A) When up is pressed, start a timer so after a set time, canjump is automatically false. This will give a stronger jump whilst having a limit

The issue is if the player must make a short jump then a long jump together, the timer might interfere. What I did in my last game was as such, except

B) have a 'jumppower' number that increases by 1 every 0.1 secs whilst up is down
have it reset to 0 when on the ground and cancel the loop when up is released
if jumppower is over a set number, cancel the loop and set canjump to false

yadah

  • Posts: 48
@unrealCanine

Do you have a playable example where I can see that jump you made in action?

LIBERADO

  • *
  • Posts: 2720
For jumping with varying strength you can use this code:
   
<a href="https://www.dropbox.com/s/ybcek9lq1uvl3s9/Variable%20Jump.swf?raw=1" target="_blank" class="new_win">https://www.dropbox.com/s/ybcek9lq1uvl3s9/Variable%20Jump.swf?raw=1</a>

« Last Edit: February 17, 2016, 06:00:18 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.

Photon

  • Posts: 2691
Very nice Liberado. The only thing I notice is the abruptness of the jump stop when you let go of the button, but that's kind of like the original Super Mario Bros. anyway, I guess. :)

As a side note though, when applying constant force the trick is to apply a strong impulse for the initial jump and then something continually afterwards that is less than the force of gravity.
Do NOT PM me your questions, because I likely will not respond. If I have replied to your question on the forum, keep using that topic. Thanks!

LIBERADO

  • *
  • Posts: 2720
@Photon, yes, there are many ways to do this kind of jump.

In my example, there are two "-10" in the last "if" code block. A lower value on that number (eg. "-20" ) would produce a less abruptness of the jump stop. It is a matter of taste. ;)

« Last Edit: October 19, 2014, 04:57:15 pm by LIBERADO »
I'm spanish, excuse me for my bad English.
I'm not a private teacher. Please, post your questions in the public forum.