Physics in my game confused after restructuring the Game loop

Posted by Julian Assange on Game Development See other posts from Game Development or by Julian Assange
Published on 2011-01-04T00:09:13Z Indexed on 2011/01/04 1:00 UTC
Read the original article Hit count: 936

Filed under:
|
|

Hello! I'm on my way with making a game in Java. Now I have some trouble with an interpolation based game loop in my calculations.

Before I used that system the calculation of a falling object was like this:

  • Delta based system

    private static final float SPEED_OF_GRAVITY = 500.0f;
    
    
    @Override
     public void update(float timeDeltaSeconds, Object parentObject) {
    
    
    parentObject.y = parentObject.y +
              (parentObject.yVelocity * timeDeltaSeconds);
    
    
    parentObject.yVelocity -= SPEED_OF_GRAVITY  * timeDeltaSeconds;
        ......
    

What you see here is that I used that delta value from previous frame to the current frame to calculate the physics. Now I switched and implement a interpolation based system and I actually left the current system where I used delta to calculate my physics.

However, with the interpolation system the delta time is removed - but now are my calculations screwed up and I've tried the whole day to solve this:

  • Interpolation based system

    private static final float SPEED_OF_GRAVITY = 500.0f;
    
    
    @Override
    public void update(Object parentObject) {
    
    
    parentObject.y = parentObject.y +
            (parentObject.yVelocity);
    
    
    parentObject.yVelocity -= SPEED_OF_GRAVITY;
        ......
    

I'm totally clueless - how should this be solved? The rendering part is solved with a simple prediction method. With the delta system I could see my object be smoothly rendered to the screen, but with this interpolation/prediction method the object just appear sticky for one second and then it's gone.

The core of this game loop is actually from here deWiTTERS Game Loop, where I trying to implement the last solution he describes.

Shortly - my physics are in a mess and this need to be solved.

Any ideas? Thanks in advance!

© Game Development or respective owner

Related posts about game-design

Related posts about java