# ODE Stepsize

This topic is 4224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I just put a few lines of ODE code into my project to begin using it, but I'm getting a weird error window when I run the project. It says that my stepsize must be greater than 0. I'm using 0.05f as a stepsize like this:
dWorldStep(world, 0.05f);

Any ideas why it's claiming I have a 0 timestep?

##### Share on other sites
Perhaps the second parameter dWorldStep takes an integer type and 0.05f gets rounded to 0?

##### Share on other sites
The function declaration is this:
void dWorldStep (dWorldID, dReal stepsize);

The demo apps for ODE use 0.05f as a stepsize, so I'm figuring that it's not getting rounded.

##### Share on other sites
Check out the end of this thread. You may be linking against the wrong version of the ODE library.

##### Share on other sites
Since you arn't controlling how fast your application runs, you need to pass in the difference of time to the step side. This means you're going to have to implement a timer to check how many milliseconds have passed since last update. It will end up being something like this:

static uint deltaTicks = 0; static uint lastTick = 0;uint currentTicks = GetTime(); // whatever you use for getting the timedeltaTicks = currentTicks - lastTick; lastTick = currentTicks; // update the last tick markerdWorldStep(world, 0.1f * deltaTicks); // 0.1 is speed modifier

##### Share on other sites
Quote:
 Original post by Jack SotacCheck out the end of this thread. You may be linking against the wrong version of the ODE library.

That turns out to be right. When I start using the binary version of ODE, it works fine. Now I just have to find a nice way to combine ODE and DirectX meshes...

##### Share on other sites
BTW, it would be well worth your time to implement a fixed timestep system.

##### Share on other sites
Quote:
 Original post by BradDaBugBTW, it would be well worth your time to implement a fixed timestep system.

##### Share on other sites
I think BradDaBug meant you should limit the maximum step size, that way things don't end up in walls (this happens in NFS-MW) or pass through things (this happens in NFSU2). If you've ever used Newton, you might have noticed this happening, since it's built-in, but in ODE, you have to do it yourself. It's not hard to do, all you have to do is get the time as you normally would, check to see if it's greater than the maximum value you've set, and if it is, set it to the maximum value instead, and then pass it off normally. Using Rob Loach's example, you'd do something like this:

...//everything before the stepdReal stepSize = 0.1f * deltaTicks;#define MAX_STEP_SIZE 0.05f //makes it a little easier to changeif (stepSize > MAX_STEP_SIZE) stepSize = MAX_STEP_SIZE;#undef MAX_STEP_SIZE//now we make the stepdWorldStep(world,stepSize);

##### Share on other sites
I put that in but now my box just keeps bouncing higher and higher and spinning faster and faster. Is there something else I can do to stop this?

##### Share on other sites
Quote:
 Original post by GoraxI think BradDaBug meant you should limit the maximum step size, that way things don't end up in walls (this happens in NFS-MW) or pass through things (this happens in NFSU2).

Although setting a maximum step size is much better than nothing, I meant fixed timesteps. The basic idea is that you set your desired timestep size to something like 0.01 (100 Hz) and then each frame figure out whether you need to take a step or not. Some frames you may not take a step (if you're game is running really fast) and some frames you might take more than one step (if your game is running slower). Whatever happens, each timestep is exactly the same size, completely independent from the frame rate.

##### Share on other sites
Sorry about that BradDaBug, I understand what you mean now (oddly enough, I've actually done it before, but a lack of sleep makes it easy to forget things). The only difference between the method I used, and the one you use, is that I assumed everybody's computers were slow, so the maximum time step was required (nothing like not being able to control anything for a few seconds while your computer chokes on something), but in order to keep it stable (so nothing got embedded in the walls, etc.), I had it run through small, fixed time steps (not unlike the ones you mentioned). It's less efficient than your method, but it'd run on (almost) anything without any problems.

NickGravelyn, incase you can't figure out what I'm rambling on about, instead of using some step size up to the maximum step size, run a loop that uses some step size up to some predetermined (smaller) step size that should ensure that nothing stupid happens during the simulation, until the step size acquried in the method I showed you is reached.

Also, your problem is probably the result of you not resetting the 'lastTick' value (I've done it before).

[EDIT]
BradDaBug, feel free to disregard everything I mentioned about my method differing from yours where it doesn't. I really need more sleep...

##### Share on other sites

This topic is 4224 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.