• entries
686
1952
• views
387966

# Checkpoints

124 views

Checkpoints are done:

off:

on:

One last thing before I can move onto level 2, controlling jump height. Meaning, determining how high a jump is by how long the button is held down. Hopefully I can get that done tomorrow, although I first have to figure out how.

Checkpoints were really needed. The first level was long.

As for making jump height proportional to the time the button is held down, this is how I would probably do it. First decide on some parameters: the maximum jump speed (maxSpeed) and the time the button must be held down to achieve this maximum speed (maxTime). Now, record the time at which the button is pressed (t1) and the time at which it is released (t2). Calculate (t2 - t1) / maxTime, clamp the result to the range [0,1], and call it normalizedTime. Now use this as a factor to interpolate linearly between 0 and maxSpeed; that is, have the character jump with speed normalizedTime * maxSpeed.

Alternatively, you could interpolate the jump height directly rather than the jump speed. From the jump height you would need to calculate the speed necessary to achieve that height (assuming you are physically simulating this with gravity acting linearly on the character's vertical speed).

Edit: On second thought, I think I may have misunderstood exactly what you are trying to do. Eh.

Blocky Man is coming along nicely; can't wait for the next demo [grin].

I actually got lucky and the higher-jumps thing was a side effect of how I designed my system. I'll try to give you an idea of how I have mine setup (hopefully I don't just confuse you lol.)

I use MinVelocityY to tell when to start falling. Then, in my Jump() method I subtract from the player's y-velocity until it reaches MinVelocityY, at which point I tell it that I should no longer be able to jump until I've hit the ground. My jump method looks something like so:
void Entity::Jump(float TimeScale)
{
if(AllowInput)
{
if(InAir || !CanJump)
return;

// Give the player an initial burst
if((int)VelocityY == 0)
VelocityY = -(Gravity * 0.25f);

// Modify VelocityY using time-scaling.
VelocityY -= ((Gravity * 2.5f) * TimeScale);

// We've reached the peak of our jump
if(VelocityY < MinVelocityY)
{
InAir = true;
CanJump = false;
}
}
}



When I fall on surface InAir is set to false and CanJump is set to true. Also, CanJump is set to false when I hit a ceiling/bottom of a platform.

Hopefully that's helpful and not just confusing [lol].

## Create an account

Register a new account