# 3d movement - not pathfinding

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

## Recommended Posts

to make things simpler let's consider your terrain is flat (so you don't really care about elevation).

You have two vectors:
- your target direction (R = TargetPoint - CurrentPos)

Assumming you normalize them.

angle ang = DIR dot R
axis A = R cross DIR (should be y axis or -y axis)

Now in order to turn your character you must rotate it around axis A with angle ang

For a real 3D case you need to adjust DIR and R (zero the y component) before normalizig them, and of course compute another rotation angle around your character's x axis.

##### Share on other sites
how would i use that since i dont use any angles for defining the movement or orientation of the character. He is controlled by a forward vector and up vector. He moves along his own axis's and such.

how can i use that with vectored directional axis's?

##### Share on other sites

Quote:
 He is controlled by a forward vector and up vector

Now after you find the angle ang, use a time of rotation (the time T you want your unit to complete it's rotation) make a rotation matrix around your up vector with the angle: and/T.

Now apply that matrix to your forward vector (and lateral vector if you have one) for T seconds and your unit should be rotated.

##### Share on other sites
i am still rewriting my code for object motion and i think what you said works but i dont have all the code for converting the 3 axis into a rotation matrix for setting the world matrix yet...the object seems to have a better movement now.

##### Share on other sites
To convert your axes in a matrix just place x axis on the first row, y axis on the second and z axis onm third, also you should place the position on the forth row.
The forth should be 0.0 except the 4x4 element wich should be 1.0, but there are some cases where this is not true (scale for ex.).
This works for DirectX but I'm not sure if you need to transpose the matrix on openGL.

##### Share on other sites
ok i got the axis's turned into the rotation and translation matrix and the object turns great now...now i need to tweak it alittle and i will have good following code so i can implement path following.

thank you all. i am working on smoothing the turn and standing still till i get the right forward vector.

Welcome, anytime

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 13
• 16
• 13
• 13
• 9
• ### Forum Statistics

• Total Topics
634454
• Total Posts
3017547
×