Skip to content

Commit 993915d

Browse files
v2.5.3
optymisation update
1 parent c0bbc78 commit 993915d

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Swing_Prediction.lua

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,15 @@ end
6363
function GetClosestEnemy(pLocal, pLocalOrigin, players)
6464
local closestDistance = 1000
6565
local maxDistance = 1000
66-
-- find clsoest enemy
66+
local closestPlayer = nil
67+
-- find closest enemy
6768
for _, vPlayer in ipairs(players) do
6869
if vPlayer ~= nil and vPlayer:IsAlive() and vPlayer:GetTeamNumber() ~= pLocal:GetTeamNumber() then
69-
vPlayerOrigin = vPlayer:GetAbsOrigin()
70-
local distance = (vPlayerOrigin - pLocalOrigin):Length()
70+
local vPlayerOrigin = vPlayer:GetAbsOrigin()
71+
local distanceX = math.abs(vPlayerOrigin.x - pLocalOrigin.x)
72+
local distanceY = math.abs(vPlayerOrigin.y - pLocalOrigin.y)
73+
local distanceZ = 0
74+
local distance = math.sqrt(distanceX * distanceX + distanceY * distanceY + distanceZ * distanceZ)
7175
if distance < closestDistance and distance <= maxDistance then
7276
closestPlayer = vPlayer
7377
closestDistance = distance
@@ -76,6 +80,8 @@ function GetClosestEnemy(pLocal, pLocalOrigin, players)
7680
end
7781
return closestPlayer
7882
end
83+
84+
7985
--[[ Global table of velocity vectors
8086
local velocitySamples = {}
8187
local maxSamples = 3 -- maximum number of samples

0 commit comments

Comments
 (0)