• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[Solved] Check if unit is facing the unit

Status
Not open for further replies.
Level 10
Joined
Jun 17, 2014
Messages
236
hello, i want to create a spell here is the description :
Thrown an flashbang into a targeted area. make any Heroes, both friends
and enemies, if they are facing towards to the flashbang, they will had a white flash in their screen for 1 Seconds, and slow for X% for 2 seconds. 700 AoE, no effect against any non-hero unit or creeps
see the images to get what i mean
9k=
attachment.php

 

Attachments

  • dea.jpg
    dea.jpg
    40.8 KB · Views: 130
Level 22
Joined
Feb 6, 2014
Messages
2,466
Pseudocode:
Code:
Pick Every Unit within some range
Set FB_Angle = Angle  from FB_Loc to Position of Picked Unit
Set Unit_Facing = Facing Of Picked Unit
Set Difference = FB_Angle - Unit_Facing
If Difference <  -180 then
  Set Difference = Difference + 360
Else
   If Difference > 180 then
      Set Difference = Difference - 360
   Endif
Endif
If Absolute Value(Difference) <= 10 then
    Blind Picked Unit
Endif

You might wanna clear the leaks.

EDIT: Acceptance Angle = 10 in this example
 
Last edited:
Level 10
Joined
Jun 17, 2014
Messages
236
i have check it and it dont work properly
here is my whole trigger
  • Check
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Check?
    • Actions
      • Unit Group - Pick every unit in (Units within 700.00 of (Target point of ability being cast)) and do (Actions)
        • Loop - Actions
          • Custom script: local player owningPlayer = GetOwningPlayer(GetEnumUnit())
          • Set Real[1] = (Angle from (Target point of ability being cast) to (Position of (Picked unit)))
          • Set Real[2] = (Facing of (Picked unit))
          • Set Real[3] = (Real[1] - Real[2])
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • Real[3] Less than -180.00
            • Then - Actions
              • Set Real[3] = (Real[3] + 360.00)
              • Game - Display to (All players) the text: (String(Real[3]))
            • Else - Actions
              • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
                • If - Conditions
                  • Real[3] Greater than 180.00
                • Then - Actions
                  • Set Real[3] = (Real[3] - 360.00)
                  • Game - Display to (All players) the text: (String(Real[3]))
                • Else - Actions
          • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
            • If - Conditions
              • (Abs(Real[3])) Less than or equal to 1000.00
            • Then - Actions
              • Custom script: call CinematicFadeForPlayer(owningPlayer, bj_CINEFADETYPE_FADEIN, 7.0, 100, 100, 100, 0)
              • Game - Display to (All players) the text: (String((Abs(Real[3]))))
              • Game - Display to (All players) the text: ((Name of (Picked unit)) + Is blinded)
            • Else - Actions
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
JASS:
function IsPointInSightOfUnit takes unit observer, real x, real y, real fov returns boolean
        local real face  = GetUnitFacing(observer)
        local real angle = bj_RADTODEG*Atan2(y - GetUnitY(observer), x - GetUnitX(observer))
        return not (RAbsBJ(face - angle) > fov and RAbsBJ(face - angle - 360.) > fov)
    endfunction
Slightly modified the function from the Field of View snippet so you dont need a unit to target.

In GUI, I would rather call this function using a custom script than creating the function in GUI.
  • set Unit = (Picked unit)
  • set X = X of TempLocation
  • set Y = Y of TempLocation
  • set Angle = 45
  • Custom script: set udg_B = IsPointInSightOfUnit(udg_Unit, udg_X, udg_Y, udg_Angle)
  • If
    • B is equal to true
  • Then
    • ----- do actions -----
 
Level 10
Joined
Jun 17, 2014
Messages
236
ehm, after learning Abs i got this formula and its worked and also searching at google
+REP for who try to help me

  • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
    • If - Conditions
      • (Abs(((Facing of (Picked unit)) - (180.00 + (Angle from (Target point of ability being cast) to (Position of (Picked unit))))))) Less than 90.00
    • Then - Actions
      • Custom script: if GetLocalPlayer() == GetOwningPlayer(GetEnumUnit()) then
      • Custom script: call CinematicFadeBJ( bj_CINEFADETYPE_FADEIN, 4, "ReplaceableTextures\\CameraMasks\\White_mask.blp", 100, 100, 100, 0 )
      • Custom script: endif
      • Game - Display to (All players) the text: (Name of (Picked unit))
    • Else - Actions
Edit : oh nuu, i cant give rep to Flux i must spreading rep firstly ~_~
 
Last edited:
Level 24
Joined
Aug 1, 2013
Messages
4,657
leak at "(Target point of ability being cast)"?

The equation is pretty simple.
He denormalizes the angle between the target and the flash.
Then he checks if the Abs of that result is smaller than 90 degrees.

IIrc, I use that method as well in my Missile System.
However, I am afraid that it wont give proper results in all cases.
I suppose that both Angle between points and facing angle of unit give a result between -179.999 and 180.
There is a problem where that 180+ makes a big problem.

Instead of fixing the formula on a weird way, I suggest you to switch the points in the calculation.
Angle between Flash and Unit -> Angle between Unit and Flash.

(Still both locations should be removed afterwards.)
 
Status
Not open for further replies.
Top