Archived

This topic is now archived and is closed to further replies.

algo for moving in the direction of object facing

This topic is 5305 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts


The following members in your world matrix form a vector that points in the direction the object is facing:

_13, _23, _33

Assuming there are no scales or skews in your matrix (if it''s just rotation and translation, there won''t be), then that vector is also normalised (it''s length == 1).

So all you have to do is multiply that vector by the distance to move and add it to the translation part of the world matrix:

vec3 direction;
direction.x = worldmatrix._13;
direction.y = worldmatrix._23;
direction.z = worldmatrix._33;

worldmatrix._41 += direction.x * DISTANCE_TO_MOVE;
worldmatrix._42 += direction.y * DISTANCE_TO_MOVE;
worldmatrix._43 += direction.z * DISTANCE_TO_MOVE;


--
Simon O''Connor
Creative Asylum Ltd
www.creative-asylum.com

Share this post


Link to post
Share on other sites