regular ticks


I got a program today using task to manage rendering, and other things like preconized.

But, because there is always a but, it seems that the task are waiting the end of the other one before starting.

I wish to have a regular step (to update ODEworld and object), that runs every 1/60e.

My task are not so regular, and can be waiting for different things and taking late.

How can I solve that?

You can’t create a task that runs at guaranteed intervals. But what you can do is examine how much time has elapsed since your task has last run, and call OdeWorld.step() (or whatever) the appropriate number of times based on that.


my problem is that I addforce each intervall, depending key pressed.

And I wondered if I Addforce 3 times because 3 intervals of 1/60 is the same that addForce One time because my intervel is bigger.

I am not sure of the results in fact. It’s why I prefer to search a solution to have more guarantees on regular interval.

Here is the basic skeleton of an ODE physics task:

stepsize = 1.0/60.0
accumulator = stepsize

def runPhysics(task):
    global accumulator
    dt = globalClock.getDt()
    # if dt exceeds this amount, time "slows down" so the sim can catch up
    if dt > 0.1:
        dt = 0.1
    accumulator += dt
    while accumulator >= stepsize:
        # do any pre-step actions here (add forces, etc.)
        accumulator -= stepsize
        # do any post-step actions here
    # do any per-frame actions here (synch nodepaths to bodies, draw stuff, etc.)
    return task.cont

it sounds great. I am on the try.

Thank you.