[SOLVED]Apply constant angular velocity when maxSubsteps > 1

Post Reply
Dor
Posts: 2
Joined: Sun Nov 07, 2010 8:48 am

[SOLVED]Apply constant angular velocity when maxSubsteps > 1

Post by Dor »

Hi,

In my game the main character is a structure made up from spheres and cubes.
Player roll this structure using mouse.

In "move" function of this structure, I apply desired angular speed - it moves as I wish, as long as framerate > 60fps.

I used to call simulation step in this way :

Code: Select all

updateMainCharacterMove(_deltaTime);
dynamicsWorld->stepSimulation(_deltaTime, 10);
I noticed, that when I got low framerate, the structure is unable to roll, and if it moves - it jitters.
I assume, that when the framerate is lower then fixedTimeStep, a couple of substeps is calculated, and the angular speed of my rolling structure is not refreshed beetween those substeps.

My workaround (pseudocode):

Code: Select all

// fixedTimeStep = 60Hz
int maxPhysicsSubsteps = deltaTime / fixedTimeStep;	 //  and clamp to [1, 10] , assume no one will play it when fps < 6
float subDeltaTime = deltaTime / maxPhysicsSubsteps;

for (int i = 0; i< maxPhysicsSubsteps; ++i)
{
        updateMainCharacterMove(_subDeltaTime);
        dynamicsWorld->stepSimulation(_subDeltaTime, 1);  // 1 - fixed - do not allow substeps
}
Is there a less dirty method to achive the same result?

Thanks
Dor
Last edited by Dor on Sat Nov 20, 2010 1:29 am, edited 1 time in total.
Antonz
Posts: 16
Joined: Wed Nov 17, 2010 10:57 am

Re: Apply constant angular velocity when maxSubsteps > 1

Post by Antonz »

Try using http://bulletphysics.org/mediawiki-1.5. ... _Callbacks
and do your update every fixed sub-step from it.
Dor
Posts: 2
Joined: Sun Nov 07, 2010 8:48 am

Re: [SOLVED]Apply constant angular velocity when maxSubsteps

Post by Dor »

Thanks Antonz!
That's exactly what I was looking for.
Post Reply