From 7ca219748dbb8927980f438cf4a0f2a791421367 Mon Sep 17 00:00:00 2001 From: shaji Date: Sat, 24 May 2025 19:46:20 +0200 Subject: [PATCH] [FIXED] Velocity is taking into account dead units for GROUP --- Moose Development/Moose/Wrapper/Group.lua | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/Moose Development/Moose/Wrapper/Group.lua b/Moose Development/Moose/Wrapper/Group.lua index fa597e461..44f313f27 100644 --- a/Moose Development/Moose/Wrapper/Group.lua +++ b/Moose Development/Moose/Wrapper/Group.lua @@ -912,15 +912,18 @@ function GROUP:GetVelocityVec3() if DCSGroup and DCSGroup:isExist() then local GroupUnits = DCSGroup:getUnits() - local GroupCount = #GroupUnits + local GroupCount = 0 local VelocityVec3 = { x = 0, y = 0, z = 0 } for _, DCSUnit in pairs( GroupUnits ) do - local UnitVelocityVec3 = DCSUnit:getVelocity() - VelocityVec3.x = VelocityVec3.x + UnitVelocityVec3.x - VelocityVec3.y = VelocityVec3.y + UnitVelocityVec3.y - VelocityVec3.z = VelocityVec3.z + UnitVelocityVec3.z + if DCSUnit:isExist() and DCSUnit:isActive() then + local UnitVelocityVec3 = DCSUnit:getVelocity() + VelocityVec3.x = VelocityVec3.x + UnitVelocityVec3.x + VelocityVec3.y = VelocityVec3.y + UnitVelocityVec3.y + VelocityVec3.z = VelocityVec3.z + UnitVelocityVec3.z + GroupCount = GroupCount + 1 + end end VelocityVec3.x = VelocityVec3.x / GroupCount @@ -1754,11 +1757,13 @@ function GROUP:GetMaxVelocity() for Index, UnitData in pairs( DCSGroup:getUnits() ) do - local UnitVelocityVec3 = UnitData:getVelocity() - local UnitVelocity = math.abs( UnitVelocityVec3.x ) + math.abs( UnitVelocityVec3.y ) + math.abs( UnitVelocityVec3.z ) + if UnitData:isExist() and UnitData:isActive() then + local UnitVelocityVec3 = UnitData:getVelocity() + local UnitVelocity = math.abs( UnitVelocityVec3.x ) + math.abs( UnitVelocityVec3.y ) + math.abs( UnitVelocityVec3.z ) - if UnitVelocity > GroupVelocityMax then - GroupVelocityMax = UnitVelocity + if UnitVelocity > GroupVelocityMax then + GroupVelocityMax = UnitVelocity + end end end