HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Detect if a unit is facing another unit or not...

10-27-2004, 12:27 AM#1
Dalten
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
-={tWiStÄr}=-
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
Kojiro
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
-={tWiStÄr}=-
that was sorta wierd.. because:
Quote:
Originally Posted by Daltan
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.
And also, I'm starting a crusade against telling people function names and exact triggers. If they can't find the function, they should take a step back and learn the trigger editor better before making a map. this was a question about how to make this work logicaly so i told him. that should be good enough or he shouldnt make this trigger.
10-27-2004, 01:34 AM#5
Dalten
Quote:
Originally Posted by Kojiro
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.

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
-={tWiStÄr}=-
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
Dalten
Quote:
Originally Posted by -={tWiStÄr}=-
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.

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
-={tWiStÄr}=-
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..