| 10-27-2004, 12:27 AM | #1 |
I am making a trigger that needs to know whether a unit is facing another unit within a 90 degree arc. Say unit A is looking at unit B, how do I detect this? This isn't like a backstab where unit B has to facing away, so I do not want to take into account what direction unit B is facing. Any help would be greatly appreciated. |
| 10-27-2004, 12:35 AM | #2 |
ok, im assuming you know how to get what angle a unit is facing and the angle between 2 points, if you dont, go find it. what you have to do, is check if the angle the unit is facing, is equal to the angle between the unit and Unit B + or - 45. |
| 10-27-2004, 12:48 AM | #3 |
Set BackStabAngle = Angle of Triggering unit to facing of Target unit - 180. If BackStabAngle = < facing angle of Target unit + 90 AND > facing angle of Target unit - 90, then do... your trigger. Got it? I think this formula should work, correct me if I'm wrong. |
| 10-27-2004, 12:55 AM | #4 | |
that was sorta wierd.. because: Quote:
|
| 10-27-2004, 01:34 AM | #5 | |
Quote:
It's not as easy as it seems, because comparing Angle between two points and facing angles are like comparing apples to oranges. Angles between two points returns values in the range of -180 to 180, where facing angle goes from 0 to 360. Your suggestion kind of worked, but only about as good as the other's i've been trying the last few hours. It worked as long as unit a was south of unit b. I think i know why, so i'll tinker with it some more, but post any more advice if you got it ;) |
| 10-27-2004, 02:03 AM | #6 |
ok, theres a function to convert negative values and greater than 360 angles to 0-360. Modulo (angle, 360) so if the angle -56 it would return 136 as the angle. so instead of using angle between points use Modulo angle between points by 360 or something like that. you shouldnt have to worry about the + or - values being under 0 or over 360 because if the angle between the points is 35 and the unit is facing 40, 40 - 45 = -5 is still within the 45 threshold of 35. |
| 10-27-2004, 02:23 AM | #7 | |
Quote:
Thanks a lot, I got it to work using a Modulo function like you suggested :) I wouldn't have thought of using that function since i remember almost nothing about it from my college algebra lol, but if i had gotten it to work it would have looked like one hell of a freaky trigger. |
| 10-27-2004, 02:33 AM | #8 |
actually, i didnt think of it, some other smart guy did, i barely know how it works. all i know is that for positive numbers it returns the remainder.. and for negative it returns.. something.. |
