Moving an object in a given direction

Started by
1 comment, last by Mavix_2008 16 years, 1 month ago
How do I move an object in a given direction? I have the rotation of the object (in degrees) stored in a float. When I used MDX what I did was I put the distance that I wanted the object to move in a variable X, then got the Y component using some maths using Tan() and the objects rotation. What I then had was how many units to move along the X axis, and how many to move along the Y axis. It would then move in the direction it was facing. I tried to use this code in XNA, but it does not want to work. Does anyone know how I can do this?
Advertisement
The normalized direction is (cos a, sin a). Multiply this direction by the distance you wish to travel and add it to the start position to get the end position.
Thanks, ToohrVyk, it works! At first it wouldn't work properly, because the object would move sideways instead of forwards. So when it draws I just add 90 degrees to its rotation and it works perfectly. Its actually the same problem that I had in my previous code, but I didn't think of rotating it. Besides, the code Im now using is 10 times shorter and less buggy.
Once again, thanks!

This topic is closed to new replies.

Advertisement