I know there are loads of engines for this on the web in mmf, and loads of advise on TDC, but IVe looked and looked, and cant find the answer to what I want,
Im making a jump that is like the Super mario jump, ie, the longer the player holds the button, the higher they, jump,
all the examples IVe found are a set jump height that works against the gravity,
this is really getting me annoyed now, because all my first platfomr attepts suffered with this, and now its the other way, I cant get it to do it when I want it to,
K.
----------------------
Time for a Sexy Party!
----------------------
All you need is have something to make the player fall that is unrelated to holding the jump button. Like a flag. Then you have control over it.
so say if the flag is on force the player to fall.
if the player is on the floor turn the flag off
if the player is holding the jump button the flag doesn't change
as soon as the player lets go off the jump button make the flag turn on
if the player has reached their jump's peak, turn the flag on
and if the player isn't standing on the ground turn the flag on
My favorite way is, if the player's vertical speed is upwards (whether thats >0 or <0 to you) and the player is not holding the jump button, then divide the player's speed by 2. It's quick enough to respond to be useful, smooth enough to adjust to not look jarring, and really simple to implement.
The biggest problem would come from if your game had other things that would give the player upward speed, like springboards, in which case you'd have to implement a flag to tell the difference between a player's jump and being launched in the air.
Do you guys seriously force your physics that way? It makes tons more sense to do it in a logical manner. Velocity is just the first derivative of position. That is, change in position over time. Acceleration is the change in velocity over time. I usually set my engines up like this to start:
Always:
--Add X Acceleration to X Velocity
--Add Y Acceleration to Y Velocity
--Add X Velocity to X Position
--Add Y Velocity to Y Position
And it's as simple as that. Setting X Acceleration to 1 will cause the velocity to increase by 1px/frame each frame. To add gravity, just set Y Acceleration to 2,or higher to increase the effects of gravity. You can modify these formulae to account for limits, too. For example, you could replace the second action with Set Y Velocity to min(Y Velocity+Y Acceleration, 10) to force a terminal velocity of 10px/frame.
Using a system like this, it's becomes very easy to manipulate the physics. While jump is held, you can subtract half the gravity value from the Y Acceleration, which will make the jump act as if there is lower gravity while the button is pressed.
Have you even been far as decided to use even go want to do look more like?
A button press might set a fixed jump height with a fixed increment.
A button being held might increase the jump height with a fixed increment.
I was gonna use acceleration and speed instead of fixed increment, but perhaps it's better to try getting the button/jump mechanism working with some simple predictable code.
And once the button/jump mechanism is working, try changing it into a jump with speed and acceleration.
The button/jump mechanism for trying out can be as simple as: increasing the y-position while the button is being held with a fixed increment, let's say 4 pixels at a time?
And just like Andy said, you need to check whether the player is still jumping or not. Set or unset a flag upon jumping and landing. That's basically all you need to do. If you change the flag into a variable, you might set a maximum number of jumps the player can make e.g. double jump!