HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

How to simulate a condition "unit is facing unit"

04-07-2007, 02:27 PM#1
Meai
I want a trigger only to fired off if the specific unit is looking at its opponent.

(There must be a way, because Ive seen a minigame in UtherParty in which a spell only works if the enemy is behind you.)

There is no GUI condition for this, afaik, but maybe there is an easy Jass way?
04-07-2007, 02:38 PM#2
Troll-Brain
Check the angle beetween the attacker and the attacked unit.

Or use the spell windwalk ('AOwk') and the field DataCX (dont know how say it in english)
EDIT: Hmm no this field is for behind not facing
04-07-2007, 02:45 PM#3
MaD[Lion]
Trigger:
Untitled Trigger 001
Events
Collapse Conditions
(Facing of (Attacking unit)) Greater than or equal to ((Angle from (Position of (Attacking unit)) to (Position of (Attacked unit))) - 10.00)
(Facing of (Attacking unit)) Less than or equal to ((Angle from (Position of (Attacking unit)) to (Position of (Attacked unit))) + 10.00)
Actions
04-07-2007, 03:06 PM#4
Meai
Wow thx for the fast answer, problem solved :D
If I wanted the attacked unit also facing the attacker, do I need to change the angles?
04-07-2007, 03:14 PM#5
Troll-Brain
Quote:
Originally Posted by Meai
Wow thx for the fast answer, problem solved :D
If I wanted the attacked unit also facing the attacker, do I need to change the angles?

Just add conditions
04-07-2007, 06:35 PM#6
MaD[Lion]
Trigger:
Untitled Trigger 001
Events
Collapse Conditions
(Facing of (Attacking unit)) Greater than or equal to ((Angle from (Position of (Attacking unit)) to (Position of (Attacked unit))) - 10.00)
(Facing of (Attacking unit)) Less than or equal to ((Angle from (Position of (Attacking unit)) to (Position of (Attacked unit))) + 10.00)
(Facing of (Attacked unit)) Greater than or equal to ((Angle from (Position of (Attacked unit)) to (Position of (Attacking unit))) - 10.00)
(Facing of (Attacked unit)) Less than or equal to ((Angle from (Position of (Attacked unit)) to (Position of (Attacking unit))) + 10.00)
Actions
04-07-2007, 06:36 PM#7
iNfraNe
this does not work around the 0 angle.
04-07-2007, 10:25 PM#8
MaD[Lion]
who cares about that
04-07-2007, 10:31 PM#9
Ammorth
Then you have a bug, and players get pissed off and stop playing.

The solution is somewhere in these forums, just use the search feature.
04-07-2007, 10:37 PM#10
grim001
maybe the player when it screws up the game? how damn lazy

Collapse JASS:
function IsUnitFacingUnit takes unit u1, unit u2, real allowedangle returns boolean
 local real xd = GetUnitX(u2) - GetUnitX(u1)
 local real yd = GetUnitY(u2) - GetUnitY(u1)
 local real a1 = GetUnitFacing(u1)
 local real a2 = Atan2(yd, xd)*bj_RADTODEG
 local real x
     if a1>a2 then
         set x=a1
         set a1=a2
         set a2=x
     endif
     set x=a2-360
     if a2-a1 > a1-x then
         set a2=x
     endif
     set x=a1-a2
     if (x<0) then
         set x = -x
     endif
     if x < allowedangle/2 then
         return true
     endif
 return false
endfunction

This always works. First param is the unit to check. Second param is the unit it's going to check for facing toward. Last one is the allowed angle difference (i.e. set it to 90 and it will return true if the unit is in a 90 degree cone in front)

This could be generalized into a function that can check for being behind or to the side of a unit fairly easily, but this is all you need to check if a unit is facing another unit.

credit to angles_getangledifference which is clearly ripped off for this function
04-08-2007, 12:18 AM#11
Pyrogasm
Some links for you:
And here's what grim001 just wrote, except in GUI:
Quote:
Originally Posted by Me
For all you hardcore GUIers, you can eliminate the JASS script alltogether by creating variables "x", "a1", and "a2", and putting this in lieu of the 2nd custom script call.
Trigger:
Set a1 = (Facing of (Triggering unit))
Set a2 = (Facing of (Attacking unit))
Set a1 = (a1 mod 360.00)
Set a2 = (a2 mod 360.00)
Collapse If (All Conditions are True) then do (Then Actions) else do (Else Actions)
Collapse If - Conditions
a1 Greater than a2
Collapse Then - Actions
Set x = a1
Set a1 = a2
Set a2 = x
Else - Actions
Set x = (a2 - 360.00)
If ((a2 - a1) Greater than (a1 - x)) then do (Set a2 = x) else do (Do nothing)
Set x = (a1 - a2)
If (x Less than 0.00) then do (Set Backstab_Angle = (x x -1.00)) else do (Set Backstab_Angle = x)