• 10
• 9
• 13
• 10
• 18

# 8 Way Movement Via Mouse Control (2D Game)

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

## Recommended Posts

Hi, Pardon me if this is a ridiculously stupid question, but here goes. My character is controlled via the mouse. When you click with the left button, he follows it. What I need is a relatively simple way to detect the angle of movement. Say, the character is at 32, 32 and the mouse is at 48, 50, how can I go about finding a simple way to detect angle? Sorry, I'm sure this is stupid, but I don't really have many options. I'm looking up math information right now, but having no luck. Thanks a lot.

##### Share on other sites
atan() or atan2()

compare the mouse position to the characters position, rise over run = slope, remember? slope~angle

Why do you need to know the angle though?
Just use a vector approach, much more direct, saves the work of doing trig stuff.

##### Share on other sites
some trig:
float angleinradians = atan2( ( mousey - charactery ) / ( mousex - characterx ) )why? because:              mouse              .             /|            / | dy = mousey - charactery           /  |character .---            dx = mousex - characterxtan( theta ) = dy / dxthustheta = arc tangent( dy / dx )

##### Share on other sites
Thanks for the help! Got it figured out now.