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);