Im 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
How can i do this?
Printable View
Im 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
How can i do this?
The first steps to coming up with an algorithm is to define the results you want for a few different situations and then generalise:
What is the scope of your Angle? Eg 0-31 (like an objects Directions) or 0-359 like an objects angle?
Also do you want everything from dir 9 to 24 to be Left and 0-8, 25-31 to be right (or for object angle: 91-270=left and 0-90, 271-359 to be right) or are you just dealing with directions that are 16 or 0 (or 180 and 0 for angles) inwhich case just use direction/16 to get 1 for left and 0 for right (or angle/180)
'Angle / 180' returns 0 for UP and 1 for DOWN.
I need it to return 0 for RIGHT and 1 for LEFT, or the other way around.
I am using 360 degree direction system ( 0 -359 ).
'Angle / 180' returns 0 for UP and 1 for DOWN.
I need it to return 0 for RIGHT and 1 for LEFT, or the other way around.
((Angle + 90) mod 360) / 180
This'll return 0 for right and 1 for left like you want.
Modulus gives the remainder of a division operation. In practice it makes a value "loop" around, so you can offset your angle and still have it be in the 0-360 range. For example:
370 mod 360 = 10
350 mod 360 = 350
360 mod 360 = 0
540 mod 360 = 180
etc.
http://en.wikipedia.org/wiki/Modulus_operation
I <3 Mod, so very useful! I use it everywhere \:D/
(XMiliseconds Mod 1000) = Seconds, (XDays Mod 7) = day of the week, etc