I wanted to ask for help to make a function for the following:
The caster's facing angle increases or decreases until its facing angle is not similar to the angle between the caster and the mouse.
Here is my attempt, but it did not work:
The caster's facing angle increases or decreases until its facing angle is not similar to the angle between the caster and the mouse.
Here is my attempt, but it did not work:
JASS:
function GetAngle takes real x1, real x2, real y1, real y2 returns real
return bj_RADTODEG * Atan2(y2 - y1, x2 - x1)
endfunction
function GetXWithOffset takes real x, real distance, real angle returns real
return x + distance * Cos(angle * bj_DEGTORAD)
endfunction
function GetYWithOffset takes real y, real distance, real angle returns real
return y + distance * Sin(angle * bj_DEGTORAD)
endfunction
function AngleDiff takes real r1 , real r2 returns real
return Acos( Cos(r1) * Cos(r2) + Sin(r1) * Sin(r2) ) * bj_RADTODEG
endfunction
JASS:
set caster = GetUnitById(this)
set cX = GetUnitX(caster)
set cY = GetUnitY(caster)
set cZ = GetUnitFlyHeight(caster)
set mouseX = GetMouseWorldX()
set mouseY = GetMouseWorldY()
set mouseAngle = GetAngle(cX, mouseX, cY, mouseY)
set cAngle = GetUnitFacing(caster)
if AngleDiff(mouseAngle, cAngle) > AIM_TURN_SPEED then
if mouseAngle > cAngle then
set newAngle = cAngle + AIM_TURN_SPEED
else
set newAngle = cAngle - AIM_TURN_SPEED
endif
set aimNewX = GetXWithOffset(cX, AIM_SFX_DIST, newAngle)
set aimNewY = GetYWithOffset(cY, AIM_SFX_DIST, newAngle)
call SetEffectX(this.aimSfx, aimNewX)
call SetEffectY(this.aimSfx, aimNewY)
call SetUnitFacing(caster, newAngle)
endif