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?
[Solved] Detect if a unit is touching the ground?
Moderator: Moderators
[Solved] Detect if a unit is touching the ground?
Last edited by yanom on 26 Nov 2012, 16:29, edited 1 time in total.
- FireStorm_
- Posts: 666
- Joined: 19 Aug 2009, 16:09
Re: Detect if a unit is touching the ground?
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.
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.