GetUnitZ()

Dryvnt

New Member
Reaction score
10
Firstly, just to those who wonder: I don't work on my system 24/7.

Secondly, i heard that GetUnitZ() can cause desyncs... Is this true?
 

Flare

Stops copies me!
Reaction score
662
GetUnitFlyHeight wo't cause desyncs (as far as I know anyway :p), but the returned value isn't very useful in alot of situations since it's the unit's height above the current terrain level (and it won't change as the terrain goes up/down). If a unit's fly height is 100 at 0 terrain height, it'll be 100 at 500 terrain height

You can create a GetUnitZ function like so:
JASS:
globals
  location Loc = Location (0, 0)
endglobals

function GetUnitZ takes unit u returns real
  call MoveLocation (Loc, GetUnitX (u), GetUnitY (u))
  return GetLocationZ (Loc) + GetUnitFlyHeight (u)
endfunction

although I believe GetLocationZ can cause desyncs if it's called on a point that is deformed (either through a spell like Thunderclap/Warstomp, or through triggers), so it could be dangerous in maps with lots of triggered deformation
 

Dryvnt

New Member
Reaction score
10
Instead of making another thread, imma just ask it in this:

Why wont my unit go up? :(

JASS:
library PhysLib

    function PhysApplyForceX takes real XForce, integer CustomID returns nothing
        set X[CustomID] = X[CustomID] + XForce //Anything above 2000 will probably make your unit go completely out of the map
    endfunction
    
    function PhysApplyForceY takes real YForce, integer CustomID returns nothing
        set Y[CustomID] = Y[CustomID] + YForce //Anything above 2000 will probably make your unit go completely out of the map
    endfunction
    
    function PhysApplyForceZ takes real ZForce, integer CustomID returns nothing
        set Z[CustomID] = Z[CustomID] + ZForce
    endfunction
    
    function PhysUpdateUnits takes nothing returns nothing
        local unit FOG
        local integer Index = 0
        local rect TurnRect = bj_mapInitialPlayableArea
        set PhysUnits = GetUnitsInRectMatching(GetWorldBounds(), null)
        set PhysNumUnits = CountUnitsInGroup(PhysUnits)
        loop
        exitwhen Index > PhysNumUnits
            set FOG = FirstOfGroup(PhysUnits)
            set CurrentUnit[Index] = FOG
            call SetUnitUserData( FOG, Index )
            if GetUnitX(FOG) > GetRectMaxX(TurnRect) or GetUnitX(FOG) < GetRectMinX(TurnRect) then
                set X[Index] = -X[Index]
            endif
            if GetUnitY(FOG) > GetRectMaxY(TurnRect) or GetUnitY(FOG) < GetRectMinY(TurnRect) then
                set Y[Index] = -Y[Index]
            endif
            set Index = Index + 1
            call GroupRemoveUnit(PhysUnits, FOG)
        endloop
        set FOG = null
    endfunction
    
    function PhysCreateUnit takes player id, integer unitid, real x, real y, real face returns unit
        call PhysUpdateUnits()
        return CreateUnit(id,unitid,x,y,face)
    endfunction
endlibrary

scope Physics initializer Start

globals
group PhysUnits
integer PhysNumUnits
real array X
real array Y
real array Z
unit array CurrentUnit
endglobals

function PhysicsMain takes nothing returns nothing
    local integer Index = 0
    local real Sign
    call PhysUpdateUnits()
    loop
    exitwhen Index > PhysNumUnits
        if X[Index] != 0 or Y[Index] != 0 or Z[Index] != 0 then
            call SetUnitX(CurrentUnit[Index], (GetUnitX(CurrentUnit[Index]) + X[Index]))
            call SetUnitY(CurrentUnit[Index], (GetUnitY(CurrentUnit[Index]) + Y[Index]))
            if X[Index] > -1 and X[Index] < 1 then
                set X[Index] = 0
            else
                set Sign = RSignBJ(X[Index])
                set X[Index] = X[Index] - ((X[Index] / (Sign * 15)) * Sign)
            endif
            if Y[Index] > -1 and Y[Index] < 1 then
                set Y[Index] = 0
            else
                set Sign = RSignBJ(Y[Index])
                set Y[Index] = Y[Index] - ((Y[Index] / (Sign * 15)) * Sign)
            endif
            if Z[Index] > 1 and -Z[Index] > 10 and GetUnitFlyHeight(CurrentUnit[Index]) < 10 then
                //set Z[Index] = 0
            else
                call BJDebugMsg(R2S(GetUnitFlyHeight(CurrentUnit[Index])))
                call UnitAddAbility(CurrentUnit[Index], 'nmdm')
                call SetUnitFlyHeight(CurrentUnit[Index], (GetUnitFlyHeight(CurrentUnit[Index]) + Z[Index]), 10000)
                call UnitRemoveAbility(CurrentUnit[Index], 'nmdm')
                set Z[Index] = Z[Index] - 0.01
            endif
        endif
    set Index = (Index + 1)
    endloop
endfunction

function Start takes nothing returns nothing
    local timer CallPhysics = CreateTimer()
    local integer Index = 0
    local unit test = CreateUnit(Player(0), 'hpea', 0, 0, 0)
    call PhysUpdateUnits()
    call PhysApplyForceZ(10,GetUnitUserData(test))
    call SetCameraTargetControllerNoZForPlayer( Player(0), test, 0, 0, false )
    call TimerStart(CallPhysics, 0.05, true, function PhysicsMain)
endfunction

endscope


This is my code, i also gotta add your function flare, but i still can't get the unit to fly :(
 

Dryvnt

New Member
Reaction score
10
My JASS from last post said:
call UnitAddAbility(CurrentUnit[Index], 'nmdm')
call SetUnitFlyHeight(CurrentUnit[Index], (GetUnitFlyHeight(CurrentUnit[Index]) + Z[Index]), 10000)
call UnitRemoveAbility(CurrentUnit[Index], 'nmdm')

:confused:
 

Dryvnt

New Member
Reaction score
10
My rawcode for flight form (Human->Campaign->Special... WAIT!!!!

Sry guys, just me being a stupid fucktard...

Was browsing in unit part of object editor, and saw Raven... Thought i was the spell...

:banghead:
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Staff online

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top