• 🏆 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!

[General] Sides Angle

Status
Not open for further replies.
Level 5
Joined
Dec 25, 2014
Messages
111
I wanna ask. Some spells like Bristleback in DotA check if it's takes damage from Rear and Sides, it reduces the damage. I know how to check the Rear (it's like less than 90 and 180 degress, am i correct?), but how about Sides?

Thanks.
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
A trigger that I made some time ago. It displays the angle from which the caster casts the spell.
Front is about 180/-180.
Rear is about 0.
Sides are about 90/-90.
  • SpellDirection
    • Events
      • Unit - A unit Starts the effect of an ability
    • Conditions
      • (Ability being cast) Equal to Cripple (Neutral Hostile)
    • Actions
      • Set AngleBetween = (Angle from (Position of (Target unit of ability being cast)) to (Position of (Triggering unit)))
      • Set AngleTarget = ((Facing of (Target unit of ability being cast)) - 180.00)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • AngleTarget Less than 0.00
        • Then - Actions
          • Set AngleTarget = (AngleTarget + 360.00)
        • Else - Actions
      • Set Result = (AngleBetween - AngleTarget)
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Result Less than -180.00
        • Then - Actions
          • Set Result = (360.00 + Result)
        • Else - Actions
      • If (All Conditions are True) then do (Then Actions) else do (Else Actions)
        • If - Conditions
          • Result Greater than 180.00
        • Then - Actions
          • Set Result = (360.00 - Result)
        • Else - Actions
      • Game - Display to (All players) the text: (String(Result))
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
Get angle from victim to attacker, get facing of victim. Subtract facing of victim from angle between victim and attacker. Put resulting angle through sin/cos and test range as appropriate. Fastest way since despite sin/cos being complex functions the JASS overhead of direct angle approaches is far greater.

Say the resulting difference angle is X.

Front 90 degrees is Cos(X) >= Cos(45 degrees)
Back 90 degrees is Cos(X) <= -Cos(45 degrees) or Cos(135 degrees)
Left 90 degrees is Sin(X) > Sin(45 degrees) or Cos(45 degrees)
Right 90 degrees is Sin(X) < -Sin(45 degrees) or Sin(225 degrees)

Be aware that there is a 1 epsilon error with the ranges, effectively an off by 1 error. However this error is so small it cannot be humanly noticed and will have no practical effect on the game play. It may not even be encountered due to how small it is.
 
Last edited:
Status
Not open for further replies.
Top