[SOLVED] setWorldTransform() slows down my objects!
Posted: Sat Jan 14, 2017 5:03 am
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:
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:
-My bullet physics collision updates are at exactly 60 frames per second with no sub-frames.
Any help would be greatly appreciated ^^.
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);
}
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));
}
Code: Select all
mpBTWorld->stepSimulation(deltaTime, 1, 1.0f / 60.0f);