From 3c5f3d6c37a5cb4b846b769fe3e2d9f31a655020 Mon Sep 17 00:00:00 2001 From: Applevangelist Date: Mon, 25 Jul 2022 08:12:28 +0200 Subject: [PATCH] UNIT - added get altitude function with AGL option --- .../Moose/Wrapper/Positionable.lua | 4 ++-- Moose Development/Moose/Wrapper/Unit.lua | 20 +++++++++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Positionable.lua b/Moose Development/Moose/Wrapper/Positionable.lua index d1ad2963e..60f3687a6 100644 --- a/Moose Development/Moose/Wrapper/Positionable.lua +++ b/Moose Development/Moose/Wrapper/Positionable.lua @@ -537,7 +537,7 @@ function POSITIONABLE:GetBoundingRadius( MinDist ) return nil end ---- Returns the altitude of the POSITIONABLE. +--- Returns the altitude above sea level of the POSITIONABLE. -- @param Wrapper.Positionable#POSITIONABLE self -- @return DCS#Distance The altitude of the POSITIONABLE. -- @return #nil The POSITIONABLE is not existing or alive. @@ -779,7 +779,7 @@ function POSITIONABLE:GetRelativeVelocity( Positionable ) return UTILS.VecNorm( vtot ) end ---- Returns the POSITIONABLE height in meters. +--- Returns the POSITIONABLE height above sea level in meters. -- @param Wrapper.Positionable#POSITIONABLE self -- @return DCS#Vec3 The height of the POSITIONABLE in meters. -- @return #nil The POSITIONABLE is not existing or alive. diff --git a/Moose Development/Moose/Wrapper/Unit.lua b/Moose Development/Moose/Wrapper/Unit.lua index 091676403..f11e84906 100644 --- a/Moose Development/Moose/Wrapper/Unit.lua +++ b/Moose Development/Moose/Wrapper/Unit.lua @@ -178,8 +178,28 @@ function UNIT:GetDCSObject() return nil end +--- Returns the unit altitude above sea level in meters. +-- @param Wrapper.Unit#UNIT self +-- @param #boolean FromGround Measure from the ground or from sea level (ASL). Provide **true** for measuring from the ground (AGL). **false** or **nil** if you measure from sea level. +-- @return #number The height of the group or nil if is not existing or alive. +function UNIT:GetAltitude(FromGround) + + local DCSUnit = Unit.getByName( self.UnitName ) + if DCSUnit then + local altitude = 0 + local point = DCSUnit.getPoint() --DCS#Vec3 + altitude = point.y + if FromGround then + local land = land.getHeight( { x = point.x, y = point.z } ) or 0 + altitude = altitude - land + end + return altitude + end + return nil + +end --- Respawn the @{Wrapper.Unit} using a (tweaked) template of the parent Group. --