Page 1 of 1
Jumping Effect (Gravity)
Posted: Thu Jun 12, 2014 8:39 pm
by Script47
So I decided to try something (which I haven't tried before) I have *attempted* to make gravity/jumping, it can be a big part of quite a few games (I mean who doesn't like jumping). It isn't perfect but I thought it was decent for first attempt. So gimmie your ideas, what you think. And any other advice.
Edit 1:
Any ideas how I could cap the insane jumping time? So user can't just keep hold of it and halo jump forever? I tried a counter but that had unexpected (and quite annoying) results.
http://tests.my-jsgames.tk/
Re: Jumping Effect (Gravity)
Posted: Thu Jun 12, 2014 8:44 pm
by Klown
Hi - Great example of a jump. If you want to limit the height of the jump to prevent someone from floating up infinitely and/or fly - I would suggest you set a max value for the jump, say 3 or 4x the height of the object or box and once that height is reached force the gravity to take over and drop the object or box.
Hope that idea helps.
Re: Jumping Effect (Gravity)
Posted: Thu Jun 12, 2014 9:20 pm
by vitinho444
When i watched 2d game dev tutorials with Allegro I had the same problem, but they way they fixed on tutorials was to create a bool
And when press jump check if that is true (meaning the player is in a platform) and if so, put it false and set the jump, then as it is false, you can no longer jump until u reach some kind of floor, so when you collide with the floor always set
I hope that helps

Re: Jumping Effect (Gravity)
Posted: Thu Jun 12, 2014 9:35 pm
by Script47
I hope that helps

[/quote]
Klown wrote:Hi - Great example of a jump. If you want to limit the height of the jump to prevent someone from floating up infinitely and/or fly - I would suggest you set a max value for the jump, say 3 or 4x the height of the object or box and once that height is reached force the gravity to take over and drop the object or box.
Hope that idea helps.
Thanks for the suggestion, I tried this and failed.
vitinho444 wrote:When i watched 2d game dev tutorials with Allegro I had the same problem, but they way they fixed on tutorials was to create a bool
And when press jump check if that is true (meaning the player is in a platform) and if so, put it false and set the jump, then as it is false, you can no longer jump until u reach some kind of floor, so when you collide with the floor always set
Yes, I think this is quite a good idea, I shall try this.

Re: Jumping Effect (Gravity)
Posted: Thu Jun 12, 2014 9:40 pm
by vitinho444
Btw have the gravity act only when platform == false, else the player will just fall through every platform.
Good luck.
Re: Jumping Effect (Gravity)
Posted: Fri Jun 13, 2014 11:58 pm
by Callan S.
Yeah, I tend to have it than when the character begins to pass through a platform from gravity, set the character to just above the platform and onplatform=true; And when onplatform==true, gravity does not work and jump is available.
Once they jump, onplatform=false; and gravity is turned on, as well as a short duration timer which gives them lift upwards on the screen that is greater than the gravity.
Re: Jumping Effect (Gravity)
Posted: Sat Jun 14, 2014 12:24 pm
by vitinho444
Callan S. wrote:Yeah, I tend to have it than when the character begins to pass through a platform from gravity, set the character to just above the platform and onplatform=true; And when onplatform==true, gravity does not work and jump is available.
Once they jump, onplatform=false; and gravity is turned on, as well as a short duration timer which gives them lift upwards on the screen that is greater than the gravity.
Yeah

Re: Jumping Effect (Gravity)
Posted: Sat Jun 14, 2014 1:30 pm
by a_bertrand
Personally I would solve the jumping totally different.
When you press the key, and you are on some ground, you put a VY (Vertical Speed) to some negative value. Over the time you add something to the value (+0.01 ?). That will slow down first the going up and then change it with a going down which accelerate and therefore reproduce the gravity.
If you want to allow a double jump you can then implement it as well, and allow 1 jump while not on the ground. The counter would reset when you touch the ground.