Hello. I'm currently working on a platform game, and I'm using Delta timing for synchronization. The problem is that my computer is rather slow, and lags often so every time a lag spike occurs, the player jumps higher than normal (Delta time compensation). Is there any way I can prevent this, or is it just an inherent flaw of using Delta time? Thanks.
Edit: Here's my code for reference
Main game loop:
player.Input( window.GetInput( ) );
deltaTime = window.GetFrameTime( ) * 60.0f; // Synchronize to 60 FPS
player.Update( deltaTime );
Player definition:
void Player::Input( const sf::Input& input )
{
if( input.IsKeyDown( sf::Key::W ) )
{
if( y >= 448.0f )
{
verticalSpeed = -6.0f;
}
}
}
void Player::Update( float deltaTime )
{
y += verticalSpeed * deltaTime;
if( y >= 448.0f )
{
verticalSpeed = 0.0f;
y = 448.0f;
}
if( y < 448.0f ) verticalSpeed += 0.1f;
sprite.SetPosition( x, y );
}