HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Attacker is infront of defender?

04-11-2006, 07:53 PM#1
Thunder_Eye
I'm having some trouble figuring out how to check if the attacker is infront of the unit(in a 60 degrees or something to the sides)

Can someone help me? I've tested some things and can figure it out, probably because I'm to tired :/

it should look something like this maybe:
Trigger:
(Facing of (Attacking Unit) Less than or equal to ((Facing of (Attacked Unit)) + 60.00)
(Facing of (Attacking Unit) Less than or equal to ((Facing of (Attacked Unit)) - 60.00)
04-11-2006, 11:42 PM#2
vile
You want the unit to be from the back, the sides, or the front?

Quote:
how to check if the attacker is infront of the unit(in a 60 degrees or something to the sides)
You are being unclear
04-12-2006, 01:51 AM#3
mmx2000
Quote:
Originally Posted by vile
You want the unit to be from the back, the sides, or the front?


You are being unclear
I think he means, the attacker hitting the target in the face.
If so, it should be (psuedo code)
variable Facing = Facing of Target Unit + 180
and then check that
( Facing of Attacking Unit <= Facing + 30 ) and ( Facing Of Attacking Unit >= Facing - 30 )

That should check if the target unit is within 60 degrees of staring the attacker right in the face.

I think >.>;

If you want it in reverse (attacker is backstabbing), just get rid of the 180.
04-12-2006, 06:28 AM#4
RaeVanMorlock
(Facing of (Attacking Unit) Less than or equal to ((Facing of (Attacked Unit)) + 60.00)
(Facing of (Attacking Unit) Greater than or equal to ((Facing of (Attacked Unit)) - 60.00)

If the unit being attacked is facing 180, then in order to be attacking from behind, you'd need to be facing 180 as well. To allow some lee-way, you can give buffer room in either direction.

So, for your example of 60 degrees... the attacking unit can be facing between 120 and 240 so the comparison should be greater than or equal to the lesser number.. and less then or equal to the bigger number.

However, if the attacked unit is facing 0 degrees, you'd conceptually have a range from 60 degrees to -60 degrees; however, WC3 would likely report -60 degrees as 300 degrees so you'd need some way to account for that discrepency.
04-12-2006, 06:55 AM#5
mmx2000
Quote:
Originally Posted by RaeVanMorlock
(Facing of (Attacking Unit) Less than or equal to ((Facing of (Attacked Unit)) + 60.00)
(Facing of (Attacking Unit) Greater than or equal to ((Facing of (Attacked Unit)) - 60.00)

If the unit being attacked is facing 180, then in order to be attacking from behind, you'd need to be facing 180 as well. To allow some lee-way, you can give buffer room in either direction.

So, for your example of 60 degrees... the attacking unit can be facing between 120 and 240 so the comparison should be greater than or equal to the lesser number.. and less then or equal to the bigger number.

However, if the attacked unit is facing 0 degrees, you'd conceptually have a range from 60 degrees to -60 degrees; however, WC3 would likely report -60 degrees as 300 degrees so you'd need some way to account for that discrepency.


I knew I'd mess that up. Thanks for pointing out my error... I hate giving bad advice >.<
04-13-2006, 02:16 AM#6
Anitarf
For better accuracy, use angle between points (positions of the attacking and attacked unit) rather than facing angle of the attacker, since that can be a bit off if the attacker attacks from a turn; it's attack will start a bit before it is actually facing the target. However, I'm not sure, but I think facing of unit and angle between points are returned differently, one between 180 and -180 and the other between 360 and 0, so you might want to watch out for that. Another thing you must look out for is the edge, what if one unit is facing 5 degrees and the other 355? The angle difference between their directions is 10 but the difference numerically is 350 (or -350). So, if you want the angle difference to be greater than -60 and less than 60, you should also check if it's greater than 300 or less than -300.
04-13-2006, 01:47 PM#7
blu_da_noob
The best way to get around what anitarf described above:
Collapse JASS:
set difference = RMaxBJ(angle1,angle2) - RMinBJ(angle1,angle2)
if difference < limit or difference > (360 - limit) then
     //your stuff here
endif

Where limit is how much variation you can have on either side (60 in this case).