• 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.

[JASS] Locking Unit heights

Status
Not open for further replies.
Level 7
Joined
Aug 19, 2009
Messages
278
Hi guys...


Well some time agao i had made a trigger to make a unit rotate around another unit and keep the height fixed as the center unit.

I did the same thing for another system but the problem is, the rotation has some humps. Well can any 1 check whats wrong

New 1(which doesn't work well)
JASS:
function Trig_KnockbackPeriodic_Actions takes nothing returns nothing
local integer n
local real z
local real z2
local real x1
local real y1
local location loc
    if (rotatecount > 0) then
        set n = 1
        loop
        exitwhen (n > rotatecount)
        set loc = GetUnitLoc(rotatecenter[n])
        set z = GetLocationZ(loc)
        call RemoveLocation(loc)
        set loc = GetUnitLoc(rotateunit[n])
        set z2 = GetLocationZ(loc)
        call RemoveLocation(loc)
        set rotatecenterx[n] = GetUnitX(rotatecenter[n])
        set rotatecentery[n] = GetUnitY(rotatecenter[n])
        set x1 = (Cos(rotateangle[n] * bj_DEGTORAD)*rotateradius[n])
        set y1 = (Sin(rotateangle[n] * bj_DEGTORAD)*rotateradius[n])
        call SetUnitX(rotateunit[n], (rotatecenterx[n] - x1))
        call SetUnitY(rotateunit[n], (rotatecentery[n] - y1))
        call SetUnitFlyHeight(rotateunit[n], (50 + z) - z2, 0)
        set rotateangle[n] = ( rotateangle[n] + rotatespeed[n] )
        if ( rotateangle[n] >= 360.00 ) then
            set rotateangle[n] = ( rotateangle[n] - 360.00 )
        endif
            if (rotatetimer[n] <= 0) then
                if (n != rotatecount) then
                    set rotatecenter[n] = rotatecenter[rotatecount]
                    set rotateunit[n] = rotateunit[rotatecount]
                    set rotatecenterx[n] = rotatecenterx[rotatecount]
                    set rotatecentery[n] = rotatecentery[rotatecount]
                    set rotateangle[n] = rotateangle[rotatecount]
                    set rotateradius[n] = rotateradius[rotatecount]
                    set rotatespeed[n] = rotatespeed[rotatecount]
                    set rotatetimer[n] = rotatetimer[rotatecount]
                endif
                set rotatecount = rotatecount - 1
            endif
            set rotatetimer[n] = rotatetimer[n] - 1
            set n = n + 1
        endloop
    endif
endfunction

//===========================================================================
function InitTrig_KnockbackPeriodic_Copy takes nothing returns nothing
    set gg_trg_KnockbackPeriodic_Copy = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_KnockbackPeriodic_Copy, 0.05 )
    call TriggerAddAction( gg_trg_KnockbackPeriodic_Copy, function Trig_KnockbackPeriodic_Actions )
endfunction

In the old one the rotation will take automatically. In the new one you need to cast a spell on the skull unit(the first cripple spell in the skill tab

Map name
Rot2 = old one
rotate = new one


Old one(which works)
JASS:
    local real z2
    local location loc = GetUnitLoc(udg_rotor)
    local real z = GetLocationZ(loc)
    local real x1 = (Cos(udg_angle * bj_DEGTORAD)*200)
    local real y1 = (Sin(udg_angle * bj_DEGTORAD)*200)
    local real x2 = GetUnitX(udg_rotor)
    local real y2 = GetUnitY(udg_rotor)
    call RemoveLocation(loc)
    call SetUnitX(udg_rot, (x2-x1))
    call SetUnitY(udg_rot, (y2-y1))
    set loc = GetUnitLoc(udg_rot)
    set z2 = GetLocationZ(loc)
    call SetUnitFlyHeight(udg_rot, (50 + z) - z2, 0)
    set udg_angle = ( udg_angle + 10.00 )
        if ( udg_angle >= 360.00 ) then
        set udg_angle = ( udg_angle - 360.00 )
        endif
    call RemoveLocation(loc)
    set loc = null
 

Attachments

  • rot2.w3x
    18.6 KB · Views: 28
  • rotate.w3x
    21.9 KB · Views: 29
Level 7
Joined
Aug 19, 2009
Messages
278
the problem is with your coordinates, the distance between the rotation point and the thing that rotates is too big, also dont turn off colision if the unit gets out of map bounds

I tried the old one setting radius as 400. Rotates well

I tried the new one with radius 200 still got humps. Don't know what to do.
:vw_wtf:

Both are basically identical.

Any1 knows any other way to do it?
 
Level 7
Joined
Aug 19, 2009
Messages
278
Bump...

I got the error sharing it so it might help you.

The error was really really small

JASS:
function Trig_KnockbackPeriodic_Actions takes nothing returns nothing
local integer n
local real z1
local real z2
local real x1
local real y1
local location loc1
local location loc2
    if (rotatecount > 0) then
        set n = 1
        loop
        exitwhen (n > rotatecount)
        set rotatecenterx[n] = GetUnitX(rotatecenter[n])
        set rotatecentery[n] = GetUnitY(rotatecenter[n])
        set x1 = (Cos(rotateangle[n] * bj_DEGTORAD)*rotateradius[n])
        set y1 = (Sin(rotateangle[n] * bj_DEGTORAD)*rotateradius[n])
        call SetUnitX(rotateunit[n], (rotatecenterx[n] - x1))
        call SetUnitY(rotateunit[n], (rotatecentery[n] - y1))
        set loc1 = GetUnitLoc(rotatecenter[n])
        set z1 = GetLocationZ(loc1)
        set loc2 = GetUnitLoc(rotateunit[n])
        set z2 = GetLocationZ(loc2)
        call SetUnitFlyHeight(rotateunit[n], (50 + z1 - z2) , 0)
        call RemoveLocation(loc1)
        call RemoveLocation(loc2)
        set rotateangle[n] = ( rotateangle[n] + rotatespeed[n] )
        if ( rotateangle[n] >= 360.00 ) then
            set rotateangle[n] = ( rotateangle[n] - 360.00 )
        endif
            if (rotatetimer[n] <= 0) then
                if (n != rotatecount) then
                    set rotatecenter[n] = rotatecenter[rotatecount]
                    set rotateunit[n] = rotateunit[rotatecount]
                    set rotatecenterx[n] = rotatecenterx[rotatecount]
                    set rotatecentery[n] = rotatecentery[rotatecount]
                    set rotateangle[n] = rotateangle[rotatecount]
                    set rotateradius[n] = rotateradius[rotatecount]
                    set rotatespeed[n] = rotatespeed[rotatecount]
                    set rotatetimer[n] = rotatetimer[rotatecount]
                endif
                set rotatecount = rotatecount - 1
            endif
            set rotatetimer[n] = rotatetimer[n] - 1
            set n = n + 1
        endloop
    endif
endfunction

//===========================================================================
function InitTrig_KnockbackPeriodic_Copy takes nothing returns nothing
    set gg_trg_KnockbackPeriodic_Copy = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_KnockbackPeriodic_Copy, 0.05 )
    call TriggerAddAction( gg_trg_KnockbackPeriodic_Copy, function Trig_KnockbackPeriodic_Actions )
endfunction
 
Status
Not open for further replies.
Top