movement with respect to angle

Recommended Posts

hello

i would like to know, after changing an object's angle to any random value, as to how do i make the object move in a straight line with respect to that angle.

Share on other sites
Assuming you mean in 2D, firstly construct a normal vector pointing in the direction:

vx=sin(angle);vy=cos(angle);

Then multiply this by the amount you wish to move:

vx*=step;vy*=step;

Then add these to the start position to move step units in the direction:

x+=vx;y+=vy;

Share on other sites
Quote:
 Original post by Aardvajkvx=sin(angle);vy=cos(angle);
Assuming the usual conventions of 0 radians/degrees corresponding to the positive x axis and positive rotations being counterclockwise, 'sin' and 'cos' should be swapped in the above.

Create an account

Register a new account

• Forum Statistics

• Total Topics
628320
• Total Posts
2982072

• 21
• 9
• 9
• 13
• 11