- Joined
- Dec 12, 2007
- Messages
- 489
Years ago, I've made a simple trigger that checks if an attacking unit is behind the attacked unit for bonus damage (typical Backstab case)
that time, I use angle comparison between facing angle of attacker and facing angle of attacked unit,
with dev as allowed deviation angle
now, I've search a bit more information about this kind of calculation,
I've come up with result that the earlier angle comparison (method A) might not work as intended on specific angle case. which is why another method is proposed:
with input:
a1 as attacked unit facing angle and
a2 as attacker unit facing angle
if output x less than dev, then it's backstab
I simplify the GUI sample provided in this thread
with
u as attacking unit and
v as attacked unit
if output is less than deviation angle, then it's backstab
my question is, which method is more fail-proof?
timewise, method B was proposed at 2007 while Maker's (method C) was 2011,
is there any case/drawback with each method?
that time, I use angle comparison between facing angle of attacker and facing angle of attacked unit,
JASS:
local real attackerFace = GetUnitFacing(GetAttacker())
local real attackedFace = GetUnitFacing(GetTriggerUnit())
if attackedFace <= (attackerFace+dev) and attackedFace >= (attackerFace-dev) then
...
endif
now, I've search a bit more information about this kind of calculation,
I've come up with result that the earlier angle comparison (method A) might not work as intended on specific angle case. which is why another method is proposed:
JASS:
function Angles_GetAngleDifference takes real a1, real a2 returns real
local real x
// The Modulo will get the co-terminal angle if the angle is less than -360 or greater than 360.
set a1=ModuloReal(a1,360)
set a2=ModuloReal(a2,360)
// makes sure angle 1 is the smaller angle. If it isn't it switches them.
if a1>a2 then
set x=a1
set a1=a2
set a2=x
endif
// Subtracts 360, to get the first negative co-terminal angle, this is then used in a comparison to check if the angle is greater than 180 (?)
set x=a2-360
if a2-a1 > a1-x then
// If it is, use the negative angle instead
set a2=x
endif
// Now, get the difference between the 2 angles.
set x=a1-a2
// If the difference is negative, make it positive and return it. If its positive, return it.
if (x<0) then
return -x
endif
return x
endfunction
a1 as attacked unit facing angle and
a2 as attacker unit facing angle
if output x less than dev, then it's backstab
I simplify the GUI sample provided in this thread
JASS:
function BackstabAngle takes unit u, unit v returns real
local real angle1 = Atan2((GetUnitY(v)-GetUnitY(u)),(GetUnitX(v)-GetUnitX(u)))*bj_RADTODEG
local real angle2 = GetUnitFacing(v)
return Acos(Cos((angle1 - angle2)*bj_DEGTORAD))*bj_RADTODEG
endfunction
u as attacking unit and
v as attacked unit
if output is less than deviation angle, then it's backstab
my question is, which method is more fail-proof?
timewise, method B was proposed at 2007 while Maker's (method C) was 2011,
is there any case/drawback with each method?