[SOLVED] setWorldTransform() slows down my objects!

Post Reply
User avatar
Solid256
Posts: 2
Joined: Sat Jan 14, 2017 4:43 am

[SOLVED] setWorldTransform() slows down my objects!

Post by Solid256 »

Hello. I have been trying to get bullet physics working with my game engine. So far (up until now that is), it has been rather successful. I have a player in a 3d scene that can collide perfectly with objects, and uses ray casting to the ground to determine it's height.

Unfortunately, whenever I need to update the players position from the ray casting, using setWorldTransform(), it seems to slow down my character by a seemingly random amount :s.

My player uses a rigid body with no gravity, and the rigid body does NOT collide with the ground, only the ray that is cast from the player collides with the ground.

The code for the setWorldTransform() portion looks something like this:

Code: Select all

void ComponentCollision::Teleport(glm::vec3 newPosition)
{
	//Reset the rigid body and motion state world transform.

	btTransform transform;

	mpBTRigidBody->getMotionState()->getWorldTransform(transform);
	transform.setOrigin(btVector3(newPosition.x, newPosition.y, newPosition.z));

	mpBTRigidBody->setWorldTransform(transform);
	mpBTRigidBody->getMotionState()->setWorldTransform(transform);
}
I've even tried removing and re-adding the rigid body to the btWorld, but that doesn't seem to fix the problem either. I find this very strange because it seems that the ray-casting works just fine and I get the correct position. Even when just inserting the SAME origin the transform started out with, the rigidBody slows down. Why is this happening?

Additional details:
-It's written in C++.
-This happens with both VSync and non-Vsync.
-I set the players speed using SetLinearVelocity().
-My collision manager is initialized like so:

Code: Select all

void CollisionManager::InitCollisionManager()
{
	//First, create the bullet physics configuration object.
	mpBTDefColConf = new btDefaultCollisionConfiguration();

	//Then, create the collision dispatcher.
	mpBTColDispatcher = new btCollisionDispatcher(mpBTDefColConf);

	//Then, create the broadphase object.
	mpBTBroadPhaseIntPairChecker = new btDbvtBroadphase();

	//Then, create the bullet physics world.
	mpBTWorld = new btDiscreteDynamicsWorld(
			mpBTColDispatcher,
			mpBTBroadPhaseIntPairChecker,
			nullptr,
			mpBTDefColConf);

	mpBTWorld->setGravity(btVector3(0.0f, -10.0f, 0.0f));
}
-My bullet physics collision updates are at exactly 60 frames per second with no sub-frames.

Code: Select all

mpBTWorld->stepSimulation(deltaTime, 1, 1.0f / 60.0f);
Any help would be greatly appreciated ^^.
Last edited by Solid256 on Sat Jan 14, 2017 6:28 am, edited 1 time in total.
User avatar
Solid256
Posts: 2
Joined: Sat Jan 14, 2017 4:43 am

Re: setWorldTransform() slows down my objects!

Post by Solid256 »

SOLVED!

Apparently btMotionState's tend to provide an 'interpolated' version of the rigidBody's position, and not the 'actual' position.

I stopped getting/setting my positions from the motion states all together, and got them directly from the rigidBodys instead, and now everything seems to work just fine.

Note to self: ONLY use motionStates for rendering purposes, not for changing positions.

Have a good day ^^.
Post Reply