Keeping a units z coordinate steady.

AdamGriffith

You can change this now in User CP.
Reaction score
69
I am working alot with projectile motion at the moment in my map and so far I dont seem to be able to make a projectile fly at a certain height no matter what the terrain is like.

Let me attempt to explain with rubbish drawings:

Correct:

Code:
-------------------------------------------

-----\            _____/--------------------\
\       \          /                                      \
\        \_____/

Incorrect:
Code:
-----\            _____/--------------------\
\       \          /                                      \
\        \_____/                                        

-----\            _____/--------------------\
\       \          /                                      \
\        \_____/


EDIT:
Drawings gone a bit funny but you can see what I mean.
 

saw792

Is known to say things. That is all.
Reaction score
280
Perhaps you could use GetLocationZ at the point where the projectile starts, then every interval set the flying height of the unit to
JASS:
(GetLocationZ(initialLoc) - GetLocationZ(currentLoc)) + Height


That is completely untested.
 

The Undaddy

Creating with the power of rage
Reaction score
55
JASS:
function GetUnitZ takes unit u returns real
    local location l = GetUnitLoc(u)
    local real z = GetLocationZ(l)
    if u != null then
        call RemoveLocation(l)
        set l = null
        return z + GetUnitFlyHeight(u)
    endif
    set l = null
    return 0.
endfunction


JASS:
function SetUnitZ takes unit u,real z returns nothing
    local location l = GetUnitLoc(u)
    if u != null then
        //call UnitAddAbility(u,'Amrf')
        //call UnitRemoveAbility(u,'Amrf')
        call SetUnitFlyHeight(u,z - GetLocationZ(l),0)
        call RemoveLocation(l)
    endif
    set l = null
endfunction


The second function will set the unit's Z absolute from the 0 height.
 

AdamGriffith

You can change this now in User CP.
Reaction score
69
Could you please post a "movement" trigger for that.
So like a timer callback function to periodically move the unit keeping the flying height constant?
I have tried but it didnt seem to work.
 

saw792

Is known to say things. That is all.
Reaction score
280
JASS:
function Callback takes nothing returns nothing
  <Recover Struct>
  local real initz = data.initz
  local location l = Location(data.x, data.y)
  local real curz = GetLocationZ(l)
  set x = ...
  set y = ...
  set z = HEIGHT + (initz - curz)
  call SetUnitFlyHeight(..., z, 0)
endfunction


That's using my (still untested) method. Using The Undaddy's method (which I suspect is the same as mine but I haven't read properly) you would simply call SetUnitZ(unit, z) every callback.
 

Viikuna

No Marlo no game.
Reaction score
265
And you need to use ground units, because Blizzards flying height smoothing thingie makes flying units move weirdly.

Just dont forget to add&remove 'Amrf'
 

The Undaddy

Creating with the power of rage
Reaction score
55
Could you please post a "movement" trigger for that.
So like a timer callback function to periodically move the unit keeping the flying height constant?
I have tried but it didnt seem to work.

JASS:
function callback takes nothing returns nothing
    local WonderStruct data = GetTheStruct()
    call SetUnitZ(data.u,data.Height)
endfunction


Simple as that ;)
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      No members online now.

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top