• 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.
  • The Hive's 22nd Icon Contest: Creep Abilities is now concluded, time to vote for your favourite set of icons! Click here to vote!
  • ✅ The POLL for Hive's Texturing Contest #34 is OPEN! Vote for the TOP 3 SKINS! 🔗Click here to cast your vote!
  • ✅ The POLL for Hive's Techtree Contest #20 is OPEN! Vote for the TOP 3 FACTIONS! 🔗Click here to cast your vote!

[Trigger] Angle difference calculation (For backstab)

Status
Not open for further replies.
so if the attacking unit is facing 359 and the attacked unit is facing 1 degree the result will show up as 358 degree diff. To be able to check if a unit is behind i use the "Diff between angle of attacking unit and casting unit is less than 90". This dosent work too well for what u suggested because it includes a lot of other calculation methods since angles maximum is only 360 then it returns to 1 again.
 
I'm not 100% sure about this, but I think this should work.

Untitled Trigger 001
Events
Unit - A unit Is attacked
Conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
((Facing of (Attacking unit)) Less than or equal to ((Facing of (Attacked unit)) + 45.00)) or ((Facing of (Attacking unit)) Less than or equal to ((Facing of (Attacked unit)) - 315.00))
((Facing of (Attacking unit)) Greater than or equal to ((Facing of (Attacked unit)) - 45.00)) or ((Facing of (Attacking unit)) Greater than or equal to ((Facing of (Attacked unit)) - 405.00))
Then - Actions
Else - Actions

What this does is checks between the 90 degree range for the angle and the angle -360 degrees. If this doesn't work, something like it should. Hope this helps...
 
Wow it's much simpler...
A = Facing of Attacker
B = Facing of Target
If -45 < (A-B) AND (A-B) < 45, then the Attacker is behind the Target.

Maybe its just me, but because of problems with 360 = 0 etc, i cant get it to work that simply on my comp. Like for example, A = 1, B = 359.
-45 not less than -358 but -358 is less than 45. Can you see the potential for problems?
 
I'll mess around with it this afternoon and see if I can get it to work. Probly just some dumb little mistake.

EDIT: Okay, this should work better...

Backstab
Events
Unit - A unit Is attacked
Conditions
(Unit-type of (Attacking unit)) Equal to Assassin ** or other conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Or - Any (Conditions) are true
Conditions
(Abs(((Facing of (Attacked unit)) - (Facing of (Attacking unit))))) Less than or equal to 45.00
(Abs(((Facing of (Attacked unit)) - (Facing of (Attacking unit))))) Greater than or equal to 315.00
Then - Actions
Wait 0.20 seconds
Unit - Kill (Triggering unit) ** or other actions
Else - Actions
Do nothing

Good luck!
 
Last edited:
Well I think it has nothing to do with the attacker's facing, just calculate the angle from the attacker's to the attacked's POSITION (prolly using Atan2), and if Absolute(ThatAngle - (The Attacked Unit's Facing))<45 then you win, he's backstabbing.

Well I think briefly it's: (att = the attacker, vic = the victim)

(Abs(Atan2((Y of (Position of att)) - (Y of (Position of vic)), (X of (Position of att)) - (X of (Position of vic))) - Facing Angle of vic)) Less Than 45
 
Does anyone know how to read advanced jass and scripts so he/she can look into the weu way of doing it? And wats "Atan2"? Is dat a jass function?

One way i see of doing this is checking the attacker's angle versus the attacked unit's angle, but dat would mean you'd have to be exactly behind...and with 360 ranges of angles, that seems as unreliable as low-%-chance critical strike...
 
Backstab
Events
Unit - A unit Is attacked
Conditions
(Unit-type of (Attacking unit)) Equal to Assassin ** or other conditions
Actions
If (All Conditions are True) then do (Then Actions) else do (Else Actions)
If - Conditions
Or - Any (Conditions) are true
Conditions
(Abs(((Facing of (Attacked unit)) - (Facing of (Attacking unit))))) Less than or equal to 45.00
(Abs(((Facing of (Attacked unit)) - (Facing of (Attacking unit))))) Greater than or equal to 315.00
Then - Actions
Wait 0.20 seconds
Unit - Kill (Triggering unit) ** or other actions
Else - Actions
Do nothing

Good luck!

Already posted solution. That should work, but if it doesnt, just tell me and I'll see if i can fix the problem...
 
It does work, but somehow it causes one bug....if you use a ranged hero then he is running away from an enemy then instantly turns around to fire, backstab activates...it think this is because the angles are calculated when he is still running away from and not when he faces the enemy....not a big problem tho and i have already incorporated it in the game. Thanks and I'll credit you in my backstab spell. Oh yeah, backstab in this game gives you bonus 120% Agi damage and does not one-hit hahaha thanks for your clear example tho.
 
Status
Not open for further replies.
Back
Top