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

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

Discuss Lua based Spring scripts (LuaUI widgets, mission scripts, gaia scripts, mod-rules scripts, scripted keybindings, etc...)

Moderator: Moderators

Post Reply
yanom
Posts: 323
Joined: 10 Jul 2009, 23:34

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

Post 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?
Last edited by yanom on 26 Nov 2012, 16:29, edited 1 time in total.
User avatar
zwzsg
Kernel Panic Co-Developer
Posts: 7049
Joined: 16 Nov 2004, 13:08

Re: Detect if a unit is touching the ground?

Post 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.
Post Reply

Return to “Lua Scripts”