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

[JASS] Help Me Please (Atan2)

Status
Not open for further replies.
Level 12
Joined
Feb 23, 2007
Messages
1,030
JASS:
local unit u = GetTriggerUnit()
local unit a = GetSpellTargetUnit()
local real x1 = GetUnitX(a)
local real x2 = GetUnitX(u)
local real y1 = GetUnitY(a)
local real y2 = GetUnitY(u)
local real angle = Atan2(y2-y1, x2-x1)

Atan2 keeps returning the wrong value. What did I do wrong?

(And yes I want the angle that way)
 
Level 12
Joined
Feb 23, 2007
Messages
1,030
JASS:
function BackstabId takes nothing returns boolean
    return GetUnitAbilityLevel(GetAttacker(),'A01L')>0
endfunction

function BackstabActions takes nothing returns nothing
local unit u = GetTriggerUnit()
local unit a = GetAttacker()
local real x1 = GetUnitX(a)
local real x2 = GetUnitX(u)
local real y1 = GetUnitY(a)
local real y2 = GetUnitY(u)
local location l2 = GetUnitLoc(u)
local location l1 = GetUnitLoc(a)
local real angle = AngleBetweenPoints(l1, l2)
//local real angle = Atan2(y2-y1, x2-x1)
local real facing = GetUnitFacing(u)

if IsUnitType(u, UNIT_TYPE_STRUCTURE) == false and RAbsBJ(ModuloReal(angle, 360) - ModuloReal(facing, 360))>90 and RAbsBJ(ModuloReal(angle, 360)-ModuloReal(facing, 360))<270 then
    call DestroyEffect(AddSpecialEffectTarget("Abilities\\Spells\\Other\\Stampede\\StampedeMissileDeath.mdl",u,"origin"))
    call UnitDamageTarget(a, u, 25+15*I2R(GetUnitAbilityLevel(a,'A01L')), true, false, ATTACK_TYPE_HERO, DAMAGE_TYPE_SPIRIT_LINK, WEAPON_TYPE_WHOKNOWS)
endif

call RemoveLocation(l1)
call RemoveLocation(l2)
set u = null
set a = null
set l2 = null
set l1 = null
endfunction

//===========================================================================
function InitTrig_Backstab takes nothing returns nothing
    local trigger t = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(t, EVENT_PLAYER_UNIT_ATTACKED)
    call TriggerAddCondition(t, Condition(function BackstabId))
    call TriggerAddAction(t, function BackstabActions)
    set t = null
endfunction

I temporarily fixed it with Points rather than Coordinates...
 
Status
Not open for further replies.
Top