Equation of a Projectile - Jumping
I am working on a program that needs an object to jump, I have been using this piece of code to make
work function.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
if (Jump == 1) {
//Jump
DeltaTime /= 1000;
ElapsedKeyTime += DeltaTime;
if (ElapsedKeyTime < JumpTime) {
PlayerPositionY += StartVelocity * ElapsedKeyTime + 0.5 * Gravity * ElapsedKeyTime * ElapsedKeyTime;
//if (PlayerPositionY > JumpHeight) PlayerPositionY = JumpHeight;
}
if (ElapsedKeyTime > JumpTime) {
PlayerPositionY -= 0.5 * Gravity * (ElapsedKeyTime - JumpTime) * (ElapsedKeyTime - JumpTime);
if (PlayerPositionY < (WindowHeight / 10)) {
PlayerPositionY = WindowHeight / 10;
Jump = 0;
ElapsedKeyTime = 0;
}
}
}
|
Improvements?
Topic archived. No new replies allowed.