• 🏆 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] Angles (how to detect a backstab attack)?

Status
Not open for further replies.
Level 7
Joined
Jul 3, 2011
Messages
251
Hey guys, got a quick question which i am unsure of, how can i check if a unit is within say 60 angle range of another units facing angle? My problem is that if i were to get the units facing angle and have 2 reals for the angle +30 and angle -30, what if one of those angles go below 0.00 or above 360.00? The reason i am asking is for an ability like backstab in DotA from rikimaru (For those of you that dont know it, if riki is facing the back of a unit, he does additional damage, but if he isnt nothing happens) however i need the check to be precise without angle errors. Rep for any help.
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
This is code for backstab, so the angle is reversed Modify it a bit. The angle to compare to is between -1 and 1. You can use Acos(Cos(a1-a2)) and use degrees in the comparison..


  • Attack GUI Copy
    • Events
      • Unit - A unit Is issued an order targeting an object
    • Conditions
    • Actions
      • -------- -------------------------------------------------- --------
      • -------- Set unit variables --------
      • -------- -------------------------------------------------- --------
      • Set u1 = (Triggering unit)
      • Set u2 = (Target unit of issued order)
      • -------- -------------------------------------------------- --------
      • -------- Set location variables --------
      • -------- -------------------------------------------------- --------
      • Set p1 = (Position of u1)
      • Set p2 = (Position of u2)
      • -------- -------------------------------------------------- --------
      • -------- Get angle from "caster" to target --------
      • -------- -------------------------------------------------- --------
      • Set r1 = (Angle from p1 to p2)
      • -------- -------------------------------------------------- --------
      • -------- Get caster facing --------
      • -------- -------------------------------------------------- --------
      • Set r2 = (Facing of u2)
      • -------- -------------------------------------------------- --------
      • -------- Get angle difference --------
      • -------- -------------------------------------------------- --------
      • Set r3 = (Cos((r1 - r2)))
      • -------- -------------------------------------------------- --------
      • -------- Clear leaks --------
      • -------- -------------------------------------------------- --------
      • Custom script: call RemoveLocation(udg_p1)
      • Custom script: call RemoveLocation(udg_p2)
      • -------- -------------------------------------------------- --------
      • Game - Display to Player Group - Player 1 (Red) the text: (String(r3))
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • r3 Greater than 0.00
        • Then - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: Backstab!
        • Else - Actions
 
Level 7
Joined
Jul 3, 2011
Messages
251
Could you tell me how i could check if the facing angle of the attacking unit and the facing angle of the attacked unit has between 150-210 difference please? Because i need this to only work if the triggering unit is behind the target.
 
Level 7
Joined
Jul 3, 2011
Messages
251
What i am trying to acomplish is so the bonus damage will only be applied if the attacking unit is behind the attacked unit, like backstab in DotA, hive or take max 30 angle difference from each side, so it doesnt have to be EXACTLY 180 difference which would be near to impossible to achieve in a normal game, since the angle would have to be perfect.
 
Level 8
Joined
Dec 9, 2009
Messages
397
Here is my backstab trigger that Maker helped me make a long time ago.

  • Slash Copy
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to (==) Slash
    • Actions
      • Set Caster = (Casting unit)
      • Set Target = (Target unit of ability being cast)
      • Set CasterAngle = (Facing of Caster)
      • Set TargetAngle = (Facing of Target)
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • TargetAngle Greater than or equal to (>=) 35.00
          • Then - Actions
            • Set TargetAngle = (TargetAngle + 45.00)
            • Set CasterAngle = (CasterAngle + 45.00)
          • Else - Actions
        • Multiple FunctionsIf (All Conditions are True) then do (Then Actions) else do (Else Actions)
          • If - Conditions
            • TargetAngle Greater than or equal to (>=) (CasterAngle - 45.00)
            • TargetAngle Less than or equal to (<=) (CasterAngle + 45.00)
          • Then - Actions
            • Set SkillDmg = (Real(((Strength of Caster (Include bonuses)) x 2)))
            • Unit - Cause Caster to damage Target, dealing SkillDmg damage of attack type Chaos and damage type Normal
            • Game - Display to (Owner of Caster), at offset (0.00, 0.00) the text: Behind
          • Else - Actions
            • Set SkillDmg = (Real((Strength of Caster (Include bonuses))))
            • Unit - Cause Caster to damage Target, dealing SkillDmg damage of attack type Chaos and damage type Normal
            • Game - Display to (Owner of Caster), at offset (0.00, 0.00) the text: Not Behind
 
Level 37
Joined
Mar 6, 2006
Messages
9,240
Here's the solution I was talking about:

Link


  • BS3
    • 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)))))) Less than 90.00
        • Then - Actions
          • Game - Display to Player Group - Player 1 (Red) the text: Backstab!
        • Else - Actions
      • Custom script: call RemoveLocation(udg_p1)
      • Custom script: call RemoveLocation(udg_p2)


Using an angle of 90 makes the checked angle 180 degress, a semi circle. The attacker needs to be behind the target.

The closer to 0 you adjust the angle, the narrower the allowed angle will be. The width of the actual angle to be checked is always double the value you compare to in the condition.
 
Level 7
Joined
Jul 3, 2011
Messages
251
Wow thanks maker! thats exactly what i was after :)

got another question though, since its -90, if i were to change that to +90 would that mean the attacker would have to be facing the attacked unit? Would be usefull to know if thats the case incase i ever want to make an ability like Gorgon's Stone Gaze.
 
Status
Not open for further replies.
Top