function Blink takes nothing returns nothing
local unit u = GetTriggerUnit()
local location lt = GetSpellTargetLoc()
local real xt = GetLocationX(lt)
local real yt = GetLocationY(lt)
local real xu = GetUnitX(u)
local real yu = GetUnitY(u)
local real xd = xt - xu
local real yd = yt - yu
local real d = SquareRoot(xd * xd + yd * yd)
local real a = (180 / 3.14159) * Atan2(yt - yu, xt - xu)
local real xa = Cos(a) * 500 + xu //Probably the problem
local real ya = Sin(a) * 500 + yu //Probably the problem
if (GetSpellAbilityId() == 'A000' ) then
if (IsTerrainPathable( xt, yt, PATHING_TYPE_WALKABILITY) == false) then
call DisplayTextToPlayer( GetOwningPlayer(u), 0, 0, "Cannot target there")
elseif ( d > 500 ) then
if (IsTerrainPathable( xa, ya, PATHING_TYPE_WALKABILITY) == false) then
call DisplayTextToPlayer( GetOwningPlayer(u), 0, 0, "Cannot target there")
else
call SetUnitX( u, xa)
call SetUnitY( u, ya)
endif
else
call SetUnitX( u, xt)
call SetUnitY( u, yt)
endif
endif
call RemoveLocation(lt)
set lt = null
set u = null
endfunction