I want to have a variable jump height when jumping (the longer the jump button is held, the higher you jump). It generally works fine, but when I set the Max FPS to different amounts, the jump height changes (lower FPS = higher jump height).
JumpState is 0 if the player is able to jump, 1 while jumping is accelerated in the air and 2 when falling.
JumpTimer is the amount how long the button has been pressed, if it reaches JumpTimerMax, JumpState is set to 2. JumpAdd is the amount that gets added to the Z velocity each tick (multiplied by DeltaSeconds)
Relevant code:
void ATestingBallBall::JumpPressed()
{
if (JumpState == 0)
{
Ball->SetPhysicsLinearVelocity(Ball->GetComponentVelocity() + FVector(0,0,JumpStart));
JumpState = 1;
JumpTimer = 0;
}
}
void ATestingBallBall::JumpReleased()
{
JumpState = 2;
}
void ATestingBallBall::Tick(float DeltaSeconds)
{
if (JumpState == 1)
{
Ball->SetPhysicsLinearVelocity(Ball->GetComponentVelocity() + FVector(0, 0, JumpAdd*DeltaSeconds));
JumpTimer += DeltaSeconds;
if (JumpTimer >= JumpTimerMax)
{
JumpState = 2;
}
}
}