Physics timestep questions
- by SSL
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