Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Delta Time and Jumping  (Read 2340 times)

0 Members and 1 Guest are viewing this topic.

JollyRoger

  • Newbie
  • *
  • Posts: 17
    • View Profile
Delta Time and Jumping
« 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 );
}

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
Delta Time and Jumping
« Reply #1 on: March 28, 2010, 08:18:14 am »
The accumulator idea suggested here would probably help.

JollyRoger

  • Newbie
  • *
  • Posts: 17
    • View Profile
Delta Time and Jumping
« Reply #2 on: March 28, 2010, 08:45:00 pm »
I think I understand now.  Thank you for the link.  That makes more sense.

 

anything