Trying to find the angle of mouse's hit position relative to the player's position

The title says it all. I’m working on a 2D game and I need help figuring out how to solve this mathematically.

Here is what I want to solve visually.

1 Like

You might find this helpful. Here’s the whole article talking about the user’s Mouse, Mouse.Position, and everything else that could be related to their mouse.

I’m assuming you want the angle between red and orange dots relative to the screen’s orientation

First thing is that you need to get the position of the orange dot relative to the red dot which can be done by local dir = orangeDot.AbsolutePosition - redDot.AbsolutePosition which should give you the direction from the red dot to the orange dot, which is the equivalent of the orange dot’s position relative to the red dot’s.

After that you’d just do local angleRadians = math.atan2(dir.Y, dir.X) for an angle in radians, then provide said angle to math.deg for your angle in degrees, which you can assign to the blue line’s Rotation property.

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.