• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

My Trig Is Rusty XD

Status
Not open for further replies.
Level 6
Joined
Apr 27, 2006
Messages
186
The trigger should do the following, move three dummy units around a unit in circles (it triggers once every 0.2 seconds). It doesn't work -.-.

Unit - Move fireDummy[(Integer A)] instantly to

(Point(((X of (Position of surroundedUnit)) + (85.00 x (Sin((200.00 - (Angle from (Position of surroundedUnit) to (Position of fireDummy[(Integer A)])))))))
,
(Point(((Y of (Position of surroundedUnit)) + (85.00 x (Sin(((Angle from (Position of surroundedUnit) to (Position of fireDummy[(Integer A)])-20))))))

What's wrong with this :S (Note some brackets messed up upon copying)?

Here's the JASS:
function Trig_Surrounded_Cosmetics_Actions takes nothing returns nothing
set bj_forLoopAIndex = 0
set bj_forLoopAIndexEnd = 2
loop
exitwhen bj_forLoopAIndex > bj_forLoopAIndexEnd
call SetUnitPositionLocFacingLocBJ( udg_fireDummy[GetForLoopIndexA()], Location(( GetLocationX(GetUnitLoc(udg_surroundedUnit)) + ( 85.00 * SinBJ(( 200.00 - AngleBetweenPoints(GetUnitLoc(udg_surroundedUnit), GetUnitLoc(udg_fireDummy[GetForLoopIndexA()])) )) ) ), ( GetLocationY(GetUnitLoc(udg_surroundedUnit)) + ( 85.00 * SinBJ(( AngleBetweenPoints(GetUnitLoc(udg_surroundedUnit), GetUnitLoc(udg_fireDummy[GetForLoopIndexA()])) - -20.00 )) ) )), GetUnitLoc(udg_surroundedUnit) )
call SetUnitAnimation( udg_fireDummy[GetForLoopIndexA()], "attack" )
set bj_forLoopAIndex = bj_forLoopAIndex + 1
endloop
endfunction

//===========================================================================
function InitTrig_Surrounded_Cosmetics takes nothing returns nothing
set gg_trg_Surrounded_Cosmetics = CreateTrigger( )
call DisableTrigger( gg_trg_Surrounded_Cosmetics )
call TriggerRegisterTimerEventPeriodic( gg_trg_Surrounded_Cosmetics, 0.20 )
call TriggerAddAction( gg_trg_Surrounded_Cosmetics, function Trig_Surrounded_Cosmetics_Actions )
endfunction
 
Last edited:
Level 11
Joined
Feb 22, 2006
Messages
752
Well, first of all 0.2 seconds won't make for smooth looking graphics, but if you want it to look choppy, then I guess it doesn't matter.

Second of all, that trigger would leak so many locations your game would turn into a slide show if that trigger was constantly running.

JASS:
constant function Surrounded_Cosmetics_Angular_Velocity takes nothing returns real
    return 20.00 * bj_DEGTORAD
endfunction

function Trig_Surrounded_Cosmetics_Actions takes nothing returns nothing
    local real x1 = GetUnitX( udg_surroundedUnit )
    local real y1 = GetUnitY( udg_surroundedUnit )
    local real x2
    local real y2
    local real angle
    local integer i = 0
    loop
        exitwhen ( i > 2 )
        set x2 = GetUnitX( udg_fireDummy[i] )
        set y2 = GetUnitY( udg_fireDummy[i] )
        set angle = Atan2( y2 - y1, x2 - x1 )
        call SetUnitPosition( udg_fireDummy[i], x2 + 85.00 * Cos( angle + Surrounded_Cosmetics_Angular_Velocity() ), y2 + 85.00 * Sin( angle + Surrounded_Cosmetics_Angular_Velocity() ) )
        call SetUnitAnimation( udg_fireDummy[i], "attack" )
        
        set i = i + 1
    endloop
endfunction

//================================================== =========================
function InitTrig_Surrounded_Cosmetics takes nothing returns nothing
    set gg_trg_Surrounded_Cosmetics = CreateTrigger( )
    call DisableTrigger( gg_trg_Surrounded_Cosmetics )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Surrounded_Cosmetics, 0.20 )
    call TriggerAddAction( gg_trg_Surrounded_Cosmetics, function Trig_Surrounded_Cosmetics_Actions )
endfunction
 
Level 6
Joined
Apr 27, 2006
Messages
186
Oh man that actually looks kinda ez XD, looks super similar to Java (so those are METHODS!).

Anyways I don't care about the memory leaks, it's just a test map (otherwise I could easily remove them), as for the code, it gave me a compiler error:
Expected end of line

Could someone just tell me what's wrong with my math?

I found a typo, maybe this will fix it: I had - -20 instead of just - 20

EDIT: Yep it worked, stupid typos -.-
 
Last edited:
Level 11
Joined
Feb 22, 2006
Messages
752
I'm not getting any syntax errors with jasscraft...

And JASS is more like the C languages than Java.

If you are trying to rotate something about a center in a circular path with respect to time, you would have to change the coordinates of the object as follows:

X Coordinate:

[previous x coordinate] + [radius of circle] * Cos( [previous angle] + [angular velocity])

Y Coordinate:

[previous y coordinate] + [radius of circle] * Sin( [previous angle] + [angular velocity])

angular velocity should be change in angle per second multiplied by duration of time in seconds between each update.

All angles are in radians (because the functions Cos and Sin in JASS work in radians, not degrees).
 
Level 6
Joined
Apr 27, 2006
Messages
186
It is a GUI trigger, and my trigger works now, it's easy trig, and there's nothing wrong with my trigger, and I bet there's also a sin function for degrees too in JASS :p. Meh, maybe not.
 
Level 20
Joined
Apr 22, 2007
Messages
1,960
There is, but it's not a native. All it does is:
JASS:
function CosBJ takes real degrees returns real
    return Cos(degrees * bj_DEGTORAD)
endfunction
So yeah, you're better off using Cos, which is a native, and works in radians.
 
Status
Not open for further replies.
Top