Original Post
I''m creating a 1942 (The old atari game, not Battlefield 1942
) game. However, I''m building it on top of an engine that I want to reuse later for more complex projects (like an RPG), so I''m also adding in certain goodies now, before integrating them becomes too much of a nightmare.
I''ve integrated ODE and have it working quite nicely. However, being that this is a game and not a simulation, I struggle to keep the physics updates constant, which I think is causing accuracy errors in the integrator. (The framerate fluctuates)
For example, occasionally when my player fires a fast-moving weapon, it immediately disappears up off the top of the screen, due, I presume, to the errors I''m inducing in my integrator. I come to this conclusion because the problem only appears when I have a lot of enemies on the screen, and the framerate has dropped.
Reading through someone else''s post a bit earlier, I saw that they run the physics at a fixed timestep, and then just interpolate the positions of the objects for the renderer.
What I''d like to know is how this is done. I presume I''ll have to run the physics at a low enough framerate so that the game''s overall framerate never drops below the physics updates (which would cause the physics timesteps to no longer be constant). Would, say 30 fps be good enough?
Then, will I basically keep track of how long ago I ran a physics update, and use that value to interpolate positions for the objects?
Also, I guess I''m going to need some way of ensuring that my interpolator calculates exactly where the object has to be when the physics is updated, so the object doesn''t jump backwards/forwards when the physics is updated. How will this be possible, because the interpolator doesn''t know what position the integrator is going to throw out for the object on the next physics update?
Should I perhaps :
1) Save the current positions of all objects
2) Simulate the physics for the next timestep at the current time
3) Interpolate from the current position to the one desired at the end of the timestep.
?
So, basically, the physics engine is always ''one step ahead'' of the renderer. Will this cause me any other problems (like non-smooth input, for example?).
Next, how do I decide how to interpolate the positions? Surely a linear interpolator would cause accelerating objects to look funny. But a quadratic one would cause similar artefacts in constant-velocity vehicles. Perhaps, as I can retrieve velocity and acceleration values from ODE, I could examine the magnitudes of these vectors to decide what kind of interpolator to use.
Lastly, do you think that all these changes will give the stability and speed increase I''m looking for. Is interpolating all these objects going to be cheaper, CPU-wise, than letting ODE just run every frame. Should I not perhaps concentrate on other ways of keeping the objects stable (like optimising my renderer).
We scratch our eternal itch
A twentieth century bitch
We are grateful for
Our Iron Lung