Physics timestep questions
        Posted  
        
            by 
                SSL
            
        on Game Development
        
        See other posts from Game Development
        
            or by SSL
        
        
        
        Published on 2011-03-07T17:34:09Z
        Indexed on 
            2011/03/08
            0:19 UTC
        
        
        Read the original article
        Hit count: 420
        
I've got a projectile working perfectly using the code below:
//initialised in loading screen
    60 is the FPS - projectilEposition and velocity are Vector3 types
gravity = new Vector3(0, -(float)9.81 / 60, 0);
//called every frame
projectilePosition += projectileVelocity;
This seems to work fine but I've noticed in various projectile examples I've seen that the elapsedtime per update is taken into account. What's the difference between the two and how can I convert the above to take into account the elapsedtime? (I'm using XNA - do I use ElapsedTime.TotalSeconds or TotalMilliseconds)?
Edit: Forgot to add my attempt at using elapsedtime, which seemed to break the physics:
projectileVelocity.Y += -(float)((9.81 * gameTime.ElapsedGameTime.TotalSeconds * gameTime.ElapsedGameTime.TotalSeconds) * 0.5f);
Thanks for the help
© Game Development or respective owner