position and rotation

Started by
12 comments, last by yahastu 15 years, 4 months ago
I came up with the same thing, except that I have to check wether the sin(direction) is 0, and if it is, in what way it is pointing (positive x, negative x, positive z or negative z) and then if I have to check if the direction is in the negative z + the negative x or both positive or one positive and one negative. Then finally I can calculate how x and z will change depending on the direction and velocity. I just thought there had to be a better and faster way. Does anyone know if there's a faster way to do it, in 3d?
Advertisement
I dont get it... if sin(direction) = 0 then it wont move along the y/z axis at all. the two angles where sin(direction) = zero is 0 and 90 wich is right and left. If the actor moves completely right or left, then it dosen't move on the horizontal axis at all...

y = y + (sin(direction) * velocity):
if direction = 90 or 0 then sin(direction) * velocity = 0 and therefore it wont move on the y axis, witch it shouldent...

So i dont see the problem. Is it something about the 3rd dimension, because if it is, then i cant help.
Sorry, I've been calculating the wrong thing all along, that's why it wasn't working. Thanks for the help ismetteren!
Quote:Original post by Hannesnisula
I'm not a mathpro but I'm willing to learn, but first I need to know what to learn.

I can rotate my character but I don't know how to make the character to move in the direction I'm looking. What do I need to learn and could someone explain basically how it works?


If you are at position X and you are looking in the direction of vector V, then you can move in that direction by adding V to X.

If you are at position X and you are looking at position Y, then the vector from X to Y = Y-X.

If you dont know what position you are looking at but you know what the angle is, then you can calculate the vector by using "soh cah toa" trigonometric relationships.

Another way to think about that is, given a vector pointing in the +x direction, and you know the counter-clockwise rotation, what direction is it looking in after being rotated? This could be discovered by using a rotation matrix:

http://mathworld.wolfram.com/RotationMatrix.html

Which simplifies down to:

x' = cosTheta*x + sinTheta*y
y' = -sinTheta*x + cosTheta*y

and your vector is defined by (x',y')

This topic is closed to new replies.

Advertisement