As you can see when there are many objects the character starts flickering (you can't see it because of gyazo but it flickers forwards and backwards). I have a renderer, physics and scripting thread. The scripting thread manages almost everything. When my character is moving it's executing this LUA code:
Code: Select all
local Pitch, Yaw, Roll = getCameraRotation();
local cx, cy, cz = getEntityPosition(ControllerEntity);
local vx, vy, vz = getEntityVelocity(ControllerEntity);
local velRot = Yaw + angle
local fx = math.cos(velRot);
local fy = vy;
local fz = math.sin(velRot);
local movingSpeed = fSync(1.53);
local yRealRot = -Yaw - angle - math.pi / 2
--setEntityPosition(ControllerEntity, cx + fx * movingSpeed, cy + fy * movingSpeed, cz + fz * movingSpeed, true);
setEntityRotation(ControllerEntity, toQuaternion(0.0, yRealRot, 0.0));
setEntityVelocity(ControllerEntity, fx * movingSpeed * 100, fy, fz * movingSpeed * 100)
Code: Select all
while (!g_Renderer->IsClosing())
{
if (g_PhysicsManager->WaitRendererComplete()) // true when render scene starts
{
g_PhysicsManager->SetUpdateState(false); // false to avoid 2 stepSimulations in the same frame.
g_PhysicsManager->UpdateQueues(); //load/remove pending rigidbodies
g_PhysicsManager->GetWorld()->stepSimulation(btScalar(1.f / (float)60.f), 3, btScalar(1.f / static_cast<float>(g_Renderer->GetFPS())));
}
g_TimeManager->Sleep<microseconds>(1); // also tried ms
}
Code: Select all
m_vecPosition = vecPos;
if (m_bUsingPhysics)
{
btTransform matTrans = m_pPhysics->m_pRigidBody->getWorldTransform();
matTrans.setOrigin(btVector3(m_vecPosition.x, m_vecPosition.y, m_vecPosition.z));
m_pPhysics->m_pRigidBody->activate(true);
m_pPhysics->m_pRigidBody->setWorldTransform(matTrans); // I tried using this without the next line
m_pPhysics->m_pRigidBody->getMotionState()->setWorldTransform(matTrans); // I also tried this one without the previous line
}
Edit: At the beginning I thought it was the friction but that couldn't be the problem since it works when there aren't a lot of entities.