Movement and rotation?
-
Guest
Movement and rotation?
I have a model rotating when I press the left and right arrow keys, but how can I make the model move in the direction that it is facing?
-
thesmileman
- Posts: 360
- Joined: Tue Feb 10, 2004 2:20 am
- Location: Lubbock, TX
This is not really that easy but not really that hard either.
What you need to do is see how far you need to go in each direction(x,y,z) based on the rotation. in order to do this you will have to do some math:
rX is the rotation is the x direction
rY is the rotation is the y direction
speed is how fast you want he object to go
PI is PI(From Math Class)
*NOTE: You will have to include the C math libraries
x = speed * cos(rX*PI/180)*cos(rY*.PI/180)
y = -speed * sin(rX*PI/180)*cos(rY*.PI/180)
z = speed *sin(rY*PI/180)
x,y, and z here are the distance that your model needs to go from its current sport so just add them to the corresponding current position of the model when the forward key is pressed and do the inverse on each when the backward key is pressed.
NOTE: I sometimes mess up "-" signs in my math so if this moves in a weird fasion then just try the negitive signs in each location. There are only nine possibilities and one of them will work though I belileve the above is right.
What you need to do is see how far you need to go in each direction(x,y,z) based on the rotation. in order to do this you will have to do some math:
rX is the rotation is the x direction
rY is the rotation is the y direction
speed is how fast you want he object to go
PI is PI(From Math Class)
*NOTE: You will have to include the C math libraries
x = speed * cos(rX*PI/180)*cos(rY*.PI/180)
y = -speed * sin(rX*PI/180)*cos(rY*.PI/180)
z = speed *sin(rY*PI/180)
x,y, and z here are the distance that your model needs to go from its current sport so just add them to the corresponding current position of the model when the forward key is pressed and do the inverse on each when the backward key is pressed.
NOTE: I sometimes mess up "-" signs in my math so if this moves in a weird fasion then just try the negitive signs in each location. There are only nine possibilities and one of them will work though I belileve the above is right.