• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Math formula request

Status
Not open for further replies.
I need a trigger to calculate position and facing interaction between two units. Is unit behind another unit, in front of it, or behind it?

My idea is to calculate the difference between the Facing angle of Unit 1 and Angle between unit 1 and unit 2, and just see if it is etc. less than 60, unit is in front or greater than 120 the unit is behind.
The problem is that World Editor returns one value between 0 and 360, and the other one between -180 and 180.

Please, I tried several times, and failed each and every time, so I really need help with this. Thankful in advance :D
 
Level 37
Joined
Mar 6, 2006
Messages
9,243

  • BS3 Copy
    • Events
      • Unit - A unit Is attacked
    • Conditions
    • Actions
      • Set u1 = (Attacking unit)
      • Set u2 = (Attacked unit)
      • Set p1 = (Position of u1)
      • Set p2 = (Position of u2)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • (Acos((Cos(((Angle from p1 to p2) - (Facing of u2)))))) Greater than 90.00
        • Then - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: Frontstab!
        • Else - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: Backstab!
      • Custom script: call RemoveLocation(udg_p1)
      • Custom script: call RemoveLocation(udg_p2)

Adjust the 90. It checks 90 in both directions, so in total it checks 180 degrees, a semi circle.
 
Status
Not open for further replies.
Top