Page 1 of 1

[Solved] Detect if a unit is touching the ground?

Posted: 25 Nov 2012, 20:49
by yanom
New to lua here. Is there a quick way to detect whether or not a non-flying unit is touching the ground or not? I.E. whether it's on the ground like it should be or if it's being tossed around. I'm currently working on a Unit Cannon for Zero-K, which picks up units (only ground units) and flings them accross the map, but I need my script to detect wether a unit is touching the ground or not.

Is there a quick Spring.XXXXXX() function for this?

Re: Detect if a unit is touching the ground?

Posted: 25 Nov 2012, 21:05
by FireStorm_

Re: Detect if a unit is touching the ground?

Posted: 26 Nov 2012, 03:32
by zwzsg
local function isTouchingGround(unitID)

local xu,yu,zu=Spring.GetUnitPosition(unitID)
local yg = Spring.GetGroundHeight(xu,zu)

return yu<yg+3

end

-- I used +3 because often units don't exactly stick to the ground,
-- so it's better to have a tolerance.