• 🏆 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!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

[JASS] what's wrong with this code?

Status
Not open for further replies.
Level 3
Joined
Sep 14, 2007
Messages
43
This code suppose to teleport a target unit infront of the caster, but it doesnt, so please tell me what's wrong with it.

JASS:
function Trig_Void_Tunnel_Conditions takes nothing returns boolean
    return GetSpellAbilityId() == 'A03T'
endfunction

function Trig_Void_Tunnel_Actions takes nothing returns nothing
    local unit u = GetTriggerUnit()
    local unit t = GetSpellTargetUnit()
    local real x = GetUnitX(u)
    local real y = GetUnitY(u)
    call TriggerSleepAction(0.1)
    call SetUnitX(t, x + Cos(bj_RADTODEG * GetUnitFacing(u)) * 130)
    call SetUnitY(t, y + Sin(bj_RADTODEG * GetUnitFacing(u)) * 130)
    set u = null
    set t = null
endfunction
//===========================================================================
function InitTrig_Void_Tunnel takes nothing returns nothing
    set gg_trg_Void_Tunnel = CreateTrigger()
    call TriggerRegisterAnyUnitEventBJ(gg_trg_Void_Tunnel, EVENT_PLAYER_UNIT_SPELL_EFFECT)
    call TriggerAddCondition(gg_trg_Void_Tunnel, Condition(function Trig_Void_Tunnel_Conditions))
    call TriggerAddAction(gg_trg_Void_Tunnel, function Trig_Void_Tunnel_Actions)
endfunction
 
Last edited by a moderator:
Level 20
Joined
Apr 22, 2007
Messages
1,960
GetUnitFacing() returns a real in degrees, not radians, so you don't use bj_RADTODEG, you use bj_DEGTORAD or CosBJ() or GetUnitFacing(u)*3.14159/180.

Also, even if you do TriggerSleepAction(0.1), the smallest amount of time TriggerSleepAction can work is 0.27 seconds (don't ask why, I don't know). You're better to use timers + globals or handle vars.

Also, watch out with SetUnitX and SetUnitY. If the targeted coordinate is outside map bounds, the map will fatal error.

EDIT: OMG POOT STOP STEALING MY POSTS!
 
Level 3
Joined
Sep 14, 2007
Messages
43
w8 there's something i dont understand.
if GetUnitFacing(u) returns degrees so why cant i just leave it that way?
why do i have to turn it to radians?
 
Level 3
Joined
Sep 14, 2007
Messages
43
so if i write shiftsin(0.5) in jass it will print pie/6 and not 30? :(
getunitface work with degs while trigo funcs work with rads... how can i tell which function work with deg and which with rads?
 
Level 40
Joined
Dec 14, 2005
Messages
10,532
Wtf is 'shiftsin'? You mean Asin?

Everything that returns angles except custom functions (including BJs like AngleBetweenPoints) and GetUnitFacing return radians.

AngleBetweenPoints would return radians, but they multiply by bj_RADTODEG before returning it.



And shouldn't this be old news to you, if you already have done trigonometry? Or are they still making you use that accursed "Degree Mode" on the calculators?
 
Level 3
Joined
Sep 14, 2007
Messages
43
i dont know, i just finished highschool and i'm much more comfortable with degrees than with radians.
 
Status
Not open for further replies.
Top