I'm having this very strange behaviour and I can't understand why...
I have a Unit class that uses a IAnimatedMeshSceneNode to represent the model. In my engine I call UpdateWorld to allow every unit to change its state according to the current action it is performing.
I set the velocity of the Unit to a given value, calculate a time span and use a x = x0 + vt to update the position.
The first update works. The model gets deslocated from the initial position according to the velocity vector but after that it just stays freezed.
Here is the code:
void CUnit::Update(void)
{
u32 timespan;
u32 currentTime = myGame->GetDevice()->getTimer()->getTime();
timespan = currentTime - m_lastTime;
timespan /= 1000; // now in seconds...
// x = x0 + v0*t
m_WorldPosition = m_WorldPosition + m_Velocity * (f32)timespan;
this->setWorldPosition(m_WorldPosition);
...
}
void setWorldPosition(core::vector3df value)
{
m_WorldPosition = value;
float yy = m_WorldPosition.Y;
float terrain_yy;
// verify if model is going under the ground
if(myGame)
{
terrain_yy = myGame->GetTerrainHeightAtPoint(m_WorldPosition, 1000.0f);
if(yy <= terrain_yy)
yy = terrain_yy;
}
m_WorldPosition.Y = yy;
if(model)
{
model->setPosition(this->m_WorldPosition);
model->updateAbsolutePosition();
}
}
What am I doing wrong?
Thanks,
Pedro