Skip to main content
GameDev.net gamedev.net
🔒 Locked

The Open Dynamics Engine

Started by slyterence May 11, 2004 at 5:22 AM 1 replies 600+ views
Original Post
slyterence
slyterence
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
We scratch our eternal itchA twentieth century bitchWe are grateful forOur Iron Lung
Squirm
Squirm

const float PhysicsFrameTime;
float LastFrameTime;

BringPhysicsUpToDate()
{
static float TimeRemaining = 0;
TimeRemaining += LastFrameTime;
while(TimeRemaining > PhysicsFrameTime)
{
StepPhysics();
TimeRemaining -= PhysicsFrameTime;
}
}


There. No matter what your frame time and the size of your physics simulation step, this will keep them in synch. It won''t even loose the rounding error between frames.

However, if your physics begins to take too long in one frame, the next frame is likely to be delayed by it, so it will perform even more steps, so it will take even longer... there will be some critical point at which your game goes all jerky and never recovers. A trap for this (like never performing more than a certain number of physics steps per frame) is probably worth adding.
szinkopa
szinkopa
I think it''s worth to measure the duration of physics update. And the timestep should be chosen based on this. Timestep should obviously more than the duration of a step (this is the real-time sim). If you increase the timestep your visual framerate will also increase. It''s a compromise: accuracy vs fps

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.