SFML community forums

Help => General => Topic started by: JollyRoger on March 28, 2010, 05:34:49 am

Title: Delta Time and Jumping
Post by: JollyRoger on March 28, 2010, 05:34:49 am
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:
Code: [Select]

player.Input( window.GetInput( ) );

deltaTime = window.GetFrameTime( ) * 60.0f; // Synchronize to 60 FPS
player.Update( deltaTime );


Player definition:
Code: [Select]

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 );
}
Title: Delta Time and Jumping
Post by: Svenstaro on March 28, 2010, 08:18:14 am
The accumulator idea suggested here (http://gafferongames.com/game-physics/fix-your-timestep/) would probably help.
Title: Delta Time and Jumping
Post by: JollyRoger on March 28, 2010, 08:45:00 pm
I think I understand now.  Thank you for the link.  That makes more sense.