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

Locking Flying heights

Status
Not open for further replies.
Level 7
Joined
Aug 19, 2009
Messages
278
How do i lock the flying height of a flying unit to a constant value?

In my case there is a projectile rotating around a unit. I want that projectile to have the same height as the unit and not go down and rise up when there are cliffs. How do i do that?

I tried setting the Flying height of the projectile to same z value of the unit around which it rotates but, it doesn't work...

here udg_rot = rotating projectle
udg_rotor = unit around which it rotates.

JASS:
function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    local location loc = GetUnitLoc(udg_rotor)
    local real z = GetLocationZ(loc)
    local real x1 = (CosBJ(udg_angle)*200)
    local real y1 = (SinBJ(udg_angle)*200)
    local real x2 = GetLocationX(GetUnitLoc(udg_rotor))
    local real y2 = GetLocationY(GetUnitLoc(udg_rotor))
    call SetUnitFlyHeight(udg_rot, z, 999)
    call SetUnitX(udg_rot, (x2-x1))
    call SetUnitY(udg_rot, (y2-y1))
    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
    call RemoveLocation(loc)
    set loc = null
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_002_Copy takes nothing returns nothing
    set gg_trg_Untitled_Trigger_002_Copy = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Untitled_Trigger_002_Copy, 0.05)
    call TriggerAddAction( gg_trg_Untitled_Trigger_002_Copy, function Trig_Untitled_Trigger_002_Actions )
endfunction
 

Attachments

  • rot2.w3x
    18.3 KB · Views: 47
Level 37
Joined
Mar 6, 2006
Messages
9,243
JASS:
function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    local location loc = GetUnitLoc(udg_rotor)
    local real z = GetLocationZ(loc)
    local real z2
    local real x1 = (CosBJ(udg_angle)*200)
    local real y1 = (SinBJ(udg_angle)*200)
    local real x2 = GetLocationX(GetUnitLoc(udg_rotor))
    local real y2 = GetLocationY(GetUnitLoc(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
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_002_Copy takes nothing returns nothing
    set gg_trg_Untitled_Trigger_002_Copy = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Untitled_Trigger_002_Copy, 0.05)
    call TriggerAddAction( gg_trg_Untitled_Trigger_002_Copy, function Trig_Untitled_Trigger_002_Actions )
endfunction

That's the basic idea to prevent it from going down, but making it no go up is impossible as far as I know since units can't be positioned under the ground level.
 
Level 7
Joined
Aug 19, 2009
Messages
278
JASS:
function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    local location loc = GetUnitLoc(udg_rotor)
    local real z = GetLocationZ(loc)
    local real z2
    local real x1 = (CosBJ(udg_angle)*200)
    local real y1 = (SinBJ(udg_angle)*200)
    local real x2 = GetLocationX(GetUnitLoc(udg_rotor))
    local real y2 = GetLocationY(GetUnitLoc(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
endfunction

//===========================================================================
function InitTrig_Untitled_Trigger_002_Copy takes nothing returns nothing
    set gg_trg_Untitled_Trigger_002_Copy = CreateTrigger(  )
    call TriggerRegisterTimerEventPeriodic( gg_trg_Untitled_Trigger_002_Copy, 0.05)
    call TriggerAddAction( gg_trg_Untitled_Trigger_002_Copy, function Trig_Untitled_Trigger_002_Actions )
endfunction

That's the basic idea to prevent it from going down, but making it no go up is impossible as far as I know since units can't be positioned under the ground level.

wow... thanks.... it works..!!

Well, you could shift the z offset of the model or inconveniently simulate cliffs/ground height in another way.

which other way?
 
Level 26
Joined
Aug 18, 2009
Messages
4,097
Yes, you use GetUnitLoc multiple times but do not clear up all instances. There is no need for locations anyway, just take GetUnitX/Y. Only for GetLocationZ a location is needed but you usually have a global one for that, whose coordinates you reset by MoveLocation rather than creating locations everytime. There is also no need for working in degrees.
 
Level 7
Joined
Aug 19, 2009
Messages
278
Yes, you use GetUnitLoc multiple times but do not clear up all instances. There is no need for locations anyway, just take GetUnitX/Y. Only for GetLocationZ a location is needed but you usually have a global one for that, whose coordinates you reset by MoveLocation rather than creating locations everytime. There is also no need for working in degrees.

whats the MoveLocation?

I fixed the other problems in it... updating my final trigger.
It was not the final trigger which i wrote. I just wanted the concept to do... it

Any way thanks.

JASS:
function Trig_Untitled_Trigger_002_Actions takes nothing returns nothing
    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
endfunction

If i remove a location, should i null it after that?
 
Last edited:
Level 26
Joined
Aug 18, 2009
Messages
4,097
whats the MoveLocation?

http://jass.sourceforge.net/doc/api/common_j-source.shtml#1002


If i remove a location, should i null it after that?

Not the location but the location variable. This is only necessary if it's a local variable (not an argument of the function). Local variables are not properly cleaned up by the engine, so references/reference-counter to objects persist. The ids of objects won't get released until they are destroyed and all references have vanished. That's why one should null local handle vars.
 
Status
Not open for further replies.
Top