I am currently working on a 2D platformer. I am trying to make jumping easier to control. What I would like is something where is you hold the jump button down longer, you jump higher. Like most 2D platformers, like Mario, have.
The problem with this is that I cant get it to look realistic. What I am doing now is I have a MAX_TIME that you can hold jump for. Then during this time period or until the jump button is released an upward acceleration is applied to the sprite. But this looks like it is floating up rather than jumping.
Here is my code so far:
JumpTime -= gameTime.ElapsedGameTime.Milliseconds;
if (JumpTime <= 0)
{
EndJump();
}
if (IsJumping)
Velocity.Y += -8 * time;
if (CurrentObjectState == ObjectState.Air)
{
Position += Velocity * time + physicsManager.GravityOverTwo * time * time;
Velocity += physicsManager.Gravity * time;
}
else
{
Position += Velocity * time;
}
Does anyone have any advice on this? Or could someone point me to a good tutorial? Every tutorial I have found just has a fixed jump that isn't affected by how long the button is held down.