Constant motion of an object (regardless of fps)

jsg007
Posts: 3
Joined: Thu Feb 17, 2011 4:14 pm

Constant motion of an object (regardless of fps)

Post by jsg007 »

Hi, in my program I'd like to have my object move over time with a constant velocity.

To do this I apply a constant force on it, and set a damping value for the body. Now the speed appears to be constant at constant fps, but if the fps varies (as it would normally in a game) movement depends on my refresh rate.

I tought Bullet should handle this, or am I doing something wrong?
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Constant motion of an object (regardless of fps)

Post by Erwin Coumans »

You will need to apply this force inside a tick callback, so it becomes framerate independent.

See bullet\Demos\DynamicControlDemo\MotorDemo.cpp for an example how to use the tick callback.
You can use a pre-tick callback to apply the force at the beginning of each simulation frame.
You can also use world set/getWorldUserInfo to point to your own custom class.

Code: Select all

bool isPreTick = true;
m_dynamicsWorld->setInternalTickCallback(motorPreTickCallback,this,isPreTick);
Thanks,
Erwin
jsg007
Posts: 3
Joined: Thu Feb 17, 2011 4:14 pm

Re: Constant motion of an object (regardless of fps)

Post by jsg007 »

Thanks for the quick reply, I'll do that.