Hi
I am writing a program using directx and I have come across a problem.
I have several models which display pathfinding behaviour but I am struggling to make the models face the direction in which they are moving.
So far my thoughts on tackling this problem are...
1) Get the distance between the model position and the goal position
2) Normalise this vector to create a direction
3) Use atan2 on the direction vector to create a rotation
4) Rotate the model the relevant amount of radians
As yet I have the models navigating towards the goal position using the direction vector created and this is working fine. When I attempt to add the rotation the results seem eratic with the model sometimes being orientated correctly. It seems like they are fine when heading in a +Z and/or a +X direction.
Although this is 3D space I am using a Y up system so have subbed the Y variables with Z. Not at my comp but from memory the code I have is...
1 2 3 4 5
|
Vector3D distance = m_position - goalNode->GetPosition();
D3DXVec3Normalize(&distance, &distance);
float rotation = atan2(distance.z, distance.y);
D3DXMatrixRotationY(&m_rotateY, rotation);
|
After this the model is transformed and rotated by m_rotateY and other transform matrices.
If anyone has any thought, suggestions or questions please let me know
Thanks