Jump to content
  • Advertisement
Sign in to follow this  
anupgupta

movement with respect to angle

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
Share on other sites
Quote:
Original post by Aardvajk

vx=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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!