 # Thread: Making and Matching Angles

1. ## Making and Matching Angles

So I need to find the angle of an object relative to another object. I learned through browsing the forums that I should use "Arc tangent of y/x", which does work. It gives a range of 360 numbers starting at -180 and ending at 180. I want all of that to be positive, so I simply added 180 to it so it's now between 0 and 360, just like an Active's angles. Unlike that though, 0 is facing directly left, instead of directly right. I've tried adding and subtracting 180 and 360 in various places, using the NOT function, but I don't get the results I want. Is there a way to fix this, or should I just keep going and find other workarounds later down the line?  Reply With Quote

2. Don't understand what you want, but here is a couple of formulas:

Detect If Angle Is Facing Left or Right -
Q: You are looking for a way to detect if an Angle is facing left or right through an expression. For example, return 0 if Angle is facing right, return 1 if Angle is facing left.
Solution:
((Angle + 90) mod 360) / 180

This will return 0 for right and 1 for left like you want.

Getting the Angle Between Two Points -
Using atn2()
atn2(X2-X1, Y2-Y1)

Marv  Reply With Quote

3. Originally Posted by nivram Don't understand what you want, but here is a couple of formulas:

Detect If Angle Is Facing Left or Right -
Q: You are looking for a way to detect if an Angle is facing left or right through an expression. For example, return 0 if Angle is facing right, return 1 if Angle is facing left.
Solution:
((Angle + 90) mod 360) / 180

This will return 0 for right and 1 for left like you want.

Getting the Angle Between Two Points -
Using atn2()
atn2(X2-X1, Y2-Y1)

Marv
Yeah, I should've been more specific. Here's a picture detailing what I currently have. Explaining Angles.jpg

Ignore this fact, but I'm making a 3D game. I need to "slide" wall graphics across the screen, and in order to make it look realistic (or even plausible) I need both the player's angle, plus the wall's angle in relation to the player (a-la using trigonometry and sine and cosine and whatnot). In the picture, if you add 1 to either angle, doesn't matter, they both rotate the same way, but 0 degrees is on the right for the Player, and 0 degrees is on the left for my calculation.

BUT

Halfway through typing this response, I was looking over yours, and I noticed that you said the formation was X2-X1, Y2-Y1. The secondary object (in this case my wall collision object) goes first, I had these values flipped around, and I had no idea that was the case. I went and flipped them back around so the wall went first and now they both are angled the same way with 0 degrees oriented in the same spot. Thank you for your help, and thank you for enabling me to try stupid things for my own amusement.  Reply With Quote

4. You had it right the first time. To get the angle between two objects is Atan2(Y2 - Y1, X1 - X2). Nivram's version is incorrect. If your 0 was left instead of right, you need to swap object 1 and object 2 around in your formula. Actually, reading your post again, you add 180 to the output. This will flip your result, not make it 0-360. Instead, set the output to (output + 360 ) mod 360.

atan2.mfa  Reply With Quote

5. Actually yeah, that's exactly what I needed, lots of decimals for as much precision as I can get too. Thanks a lot!  Reply With Quote

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•