I created box and move it with physics. Problem is, when physic object is moving, the box (drawable) have “lags”. If physics is under debug mode, collision box moving perfectly smooth, but box as drawable object is not smooth.
here is video how it looks like
I dont know where can be problem.
Here is code which can be related. Btw I fogrot create PhysicsWorld component (and it works), but after create it, it didnt help.
void MyGApp::Start()
{
scene_ = new Scene(context_);
scene_->CreateComponent<Octree>();
scene_->CreateComponent<DebugRenderer>();
PhysicsWorld * pw = scene_->CreateComponent<PhysicsWorld>();
// ...
}
void Urho3D::PlayerShip::mf_Start(Scene * scene)
{
// ...
m_node = scene->CreateChild("Spaceship");
m_node->SetPosition(Vector3(0, -2.0, -10.0f));
//m_node->SetRotation(Quaternion(0, 0, 0));
m_node->SetScale(Vector3(1.0f, 1.0f, 1.0f));
// Static model
m_node_spaceship = m_node->CreateChild("Spaceship_model");
m_spaceship = m_node_spaceship->CreateComponent<StaticModel>();
m_spaceship->SetModel(cache->GetResource<Model>("Models/Box.mdl")); // Spaceship1
m_spaceship->SetMaterial(cache->GetResource<Material>("Materials/Stone.xml"));
m_spaceship->SetCastShadows(true);
// Physics
m_spaceship_rb = m_node_spaceship->CreateComponent<RigidBody>();
m_spaceship_rb->SetMass(5.0f);
m_spaceship_rb->SetFriction(0.5f);
m_spaceship_rb->SetUseGravity(false);
m_spaceship_rb->SetCollisionEventMode(COLLISION_ALWAYS);
m_spaceship_rb->SetCcdRadius(0.1f);
m_spaceship_rb->SetCcdMotionThreshold(0.1f);
CollisionShape * collision_shape = m_node_spaceship->CreateComponent<CollisionShape>();
collision_shape->SetBox(Vector3(1.0f , 1.0f, 1.0f));
// ---------------------------------------------------------------------------
// ...
}
void Urho3D::PlayerShip::mf_Update(StringHash eventType, VariantMap & eventData)
{
float timeStep = eventData[Update::P_TIMESTEP].GetFloat();
m_node_camera->LookAt(m_spaceship_rb->GetPosition());
if (m_under_control)
{
MoveDirection = Vector3::ZERO;
float MS = m_speed; // m_speed = 2.0f;
if (input->GetKeyDown(KEY_SHIFT))
{
MS *= 10;
}
if (input->GetKeyDown(KEY_UP))
{
MoveDirection += (Vector3(0, 0, 1.0f) * MS);
}
if (input->GetKeyDown(KEY_DOWN))
{
MoveDirection += (Vector3(0, 0, -1.0f) * MS);
}
if (input->GetKeyDown(KEY_LEFT))
{
MoveDirection += (Vector3(-1.0f, 0, 0) * MS);
}
if (input->GetKeyDown(KEY_RIGHT))
{
MoveDirection += (Vector3(1.0f, 0, 0) * MS);
}
}
const Quaternion& rot = m_node_spaceship->GetRotation();
m_spaceship_rb->ApplyImpulse(MoveDirection);
m_node_spaceship->SetRotation(m_node->GetRotation());
const Vector3& velocity = m_spaceship_rb->GetLinearVelocity();
Vector3 brakeForce = (-velocity * 0.2f);
m_spaceship_rb->ApplyImpulse(brakeForce);
}