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/
Jumping Effect (Gravity)
Re: Jumping Effect (Gravity)
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.
Hope that idea helps.
if( $myGames != "Crap" ) {
- please_donate( $money );
- just_enjoy();
- vitinho444
- Posts: 2819
- Joined: Mon Mar 21, 2011 4:54 pm
Re: Jumping Effect (Gravity)
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
Code: Select all
platform = false;
Code: Select all
platform = true;
Re: Jumping Effect (Gravity)
I hope that helps [/quote]
Thanks for the suggestion, I tried this and failed.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.
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 boolAnd 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 setCode: Select all
platform = false;
Yes, I think this is quite a good idea, I shall try this.Code: Select all
platform = true;
- vitinho444
- Posts: 2819
- Joined: Mon Mar 21, 2011 4:54 pm
Re: Jumping Effect (Gravity)
Btw have the gravity act only when platform == false, else the player will just fall through every platform.
Good luck.
Good luck.
Re: Jumping Effect (Gravity)
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.
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.
- vitinho444
- Posts: 2819
- Joined: Mon Mar 21, 2011 4:54 pm
Re: Jumping Effect (Gravity)
YeahCallan 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.
- a_bertrand
- Posts: 1536
- Joined: Mon Feb 25, 2013 1:46 pm
Re: Jumping Effect (Gravity)
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.
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.
Creator of Dot World Maker
Mad programmer and annoying composer
Mad programmer and annoying composer