Setting the "z" offset of a unit?

DeepThought

New Member
Reaction score
1
There is a way to detect the "z" of a unit with the function: GetLocationZ(). I am wondering if there is a function to set the "z" of a unit.

What I am trying to do is that if a unit walks off of a non-blizzard cliff, they actually fall downward, like in real life.

Flying hight is ineffective because flying hight sets their "z" hight to the value entered for the fly hight + the "z" of the current ground. I want to just set the unit's "z", not the units "z" plus the ground.

If there is no way to simply set the unit's "Z" through a function, then can someone tell me a way how I might be able to fake this?
 

Builder Bob

Live free or don't
Reaction score
249
There is a way to detect the "z" of a unit with the function: GetLocationZ(). I am wondering if there is a function to set the "z" of a unit.

What I am trying to do is that if a unit walks off of a non-blizzard cliff, they actually fall downward, like in real life.

Flying hight is ineffective because flying hight sets their "z" hight to the value entered for the fly hight + the "z" of the current ground. I want to just set the unit's "z", not the units "z" plus the ground.

If there is no way to simply set the unit's "Z" through a function, then can someone tell me a way how I might be able to fake this?

You mentioned two things which makes me think you already know the answer.
  • GetLocationZ()
  • GetUnitFlyHeight() / SetUnitFlyHeight()

With those two functions you can know the height of the ground beneath the unit, and how high the unit is above that ground. Manipulating those should give you the desired effect.

I use a library with the functions GetTerrainZ(), GetUnitZ, and SetUnitZ(). Hope you figure it out. (I can of course provide the functions if you don't enjoy creating them yourself.)
 

DeepThought

New Member
Reaction score
1
I tried creating said functions, but to no avail. I am probably capable of creating them, but they will probably be more convoluted then necessary. Either way, it would be more convenient if you would provide these functions to me, if you are willing to :)

Sorry for the late response, by the way.
 

Builder Bob

Live free or don't
Reaction score
249
No problem

This library requires that you use Jass NewGen
JASS:
library UnitZ

globals
	private location Loc = Location(0., 0.)
endglobals

function GetTerrainZ takes real x, real y returns real
	call MoveLocation(Loc, x, y)
	return GetLocationZ(Loc)
endfunction

function GetUnitZ takes unit whichUnit returns real
	return GetTerrainZ(GetUnitX(whichUnit), GetUnitY(whichUnit)) + GetUnitFlyHeight(whichUnit)
endfunction

function SetUnitZ takes unit whichUnit, real newZ returns nothing
	call SetUnitFlyHeight(whichUnit, newZ - GetTerrainZ(GetUnitX(whichUnit), GetUnitY(whichUnit)), 0.)
endfunction

endlibrary


If you're using the GUI, you can call the functions with the following custom scripts:
Code:
Custom script:   call GetTerrainZ(x, y)
Custom script:   call GetUnitZ(whichUnit)
Custom script:   call SetUnitZ(whichUnit, newZ)
replace x and y with real variables or real values
replace whichUnit with a unit variable
replace newZ with a real variable

In case you for any reason don't use or don't want to use Jass NewGen, you can use this instead. If you do you will need to create a point variable named Loc
JASS:
function GetTerrainZ takes real x, real y returns real
	call MoveLocation(udg_Loc, x, y)
	return GetLocationZ(udg_Loc)
endfunction

function GetUnitZ takes unit whichUnit returns real
	return GetTerrainZ(GetUnitX(whichUnit), GetUnitY(whichUnit)) + GetUnitFlyHeight(whichUnit)
endfunction

function SetUnitZ takes unit whichUnit, real newZ returns nothing
	call SetUnitFlyHeight(whichUnit, newZ - GetTerrainZ(GetUnitX(whichUnit), GetUnitY(whichUnit)), 0.)
endfunction
 

DeepThought

New Member
Reaction score
1
Wow, this is incredibly useful. Thanks!

I would give you rep for that, but I already gave you rep for your previous post and the forum won't allow it.
 
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