CharacterController time synchronization

Saturnain
Posts: 4
Joined: Sun Mar 13, 2011 7:36 pm

CharacterController time synchronization

Post by Saturnain »

Hi,

I'm trying to use the btKinematicCharacterController for my game but I have a problem related to time synchronization.
I tried a lot of things but I can't make it work properly.

Here is the pertinent code:

Very simple bullet initialisation

Code: Select all

	//Bullet initialisation.
	broadphase = new btAxisSweep3(btVector3(-5000,-5000,-5000), btVector3(5000,5000,5000), 1024);
	btOverlappingPairCallback* m_ghostPairCallback = new btGhostPairCallback();
	broadphase->getOverlappingPairCache()->setInternalGhostPairCallback(m_ghostPairCallback);
	collision_configuration = new btDefaultCollisionConfiguration();
	dispatcher = new btCollisionDispatcher(collision_configuration);
	sequential_impulse_constraint_solver = new btSequentialImpulseConstraintSolver();

	world = new btDiscreteDynamicsWorld(dispatcher, broadphase, sequential_impulse_constraint_solver, collision_configuration);
	world->setGravity(btVector3(0,-20.0f,0));
The main loop :

Code: Select all

	btClock timer;
	timer.reset();
	
	while(true) 
	{
		if(timer.getTimeMilliseconds() > 16) {
			world->stepSimulation((float)timer.getTimeMicroseconds()*0.000001f, 10);
			timer.reset();
		}
		sf::Sleep(0.001f);
	}
The CharacterController update, called by a world->setInternalTickCallback (p_time is delta time)

Code: Select all

		character_controller->setWalkDirection(
			btVector3(
				Ogre::Math::Cos( angle ) * speed * 2.0f * p_time,
				0,
				Ogre::Math::Sin( angle ) * speed * 2.0f * p_time));
The character is moving a lot slower in debug mode than in release mode. I can't figure out why.
As it's a networked application, I really need to synchronize object on the time.

Thanks to read this.

(English isn't my native language)
Saturnain
Posts: 4
Joined: Sun Mar 13, 2011 7:36 pm

Re: CharacterController time synchronization

Post by Saturnain »

I guess I'm not the first one to try to make object movement independant of framerate (even in a dedicated thread for Bullet).

And I guess the stepSimulation method and his arguments are made to accomplish that.

So, I wonder if the problem could be related to the character controller implementation (I'm using the one from the sdk). I already checked but I think I'm not able yet to understand where is the problem.

Any helps, advices are welcome !
Paril
Posts: 18
Joined: Tue Feb 22, 2011 4:14 am

Re: CharacterController time synchronization

Post by Paril »

In Debug, Bullet does tons more checks and things, which can slow a fine-running 500 fps Release program down to 35 fps in Debug, depending on how everything is set up.

You might want to ensure that your FPS loop is always staying at about the same speed; it's possible that this is related to sub-steps, where it's stepping the physics twice but going behind in graphics.

-P
Saturnain
Posts: 4
Joined: Sun Mar 13, 2011 7:36 pm

Re: CharacterController time synchronization

Post by Saturnain »

In fact, I talked about Debug mode just for the example.
If I charge my scene (and so the physic world too) in release mode, my character will loose speed too. Proportionately to the charge... more I'm adding, less my character is fast.

With the if(timer.getTimeMilliseconds() > 16) , Im trying to avoid a too fast updating for the release mode. I guess the difference shouldn't be so huge.
Saturnain
Posts: 4
Joined: Sun Mar 13, 2011 7:36 pm

Re: CharacterController time synchronization

Post by Saturnain »

Saturnain wrote: The main loop :

Code: Select all

	btClock timer;
	timer.reset();
	
	while(true) 
	{
		if(timer.getTimeMilliseconds() > 16) {
			world->stepSimulation((float)timer.getTimeMicroseconds()*0.000001f, 10);
			timer.reset();
		}
		sf::Sleep(0.001f);
	}
If someone is as stupid as me, and has the same problem than I had, just reset the timer before update physic.