Skip to content

Commit

Permalink
nearest_life aim part fix
Browse files Browse the repository at this point in the history
use supplied world position of CalcAngles
  • Loading branch information
pingu7867 committed Nov 16, 2023
1 parent 49e586c commit 4fb95a8
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions lua/pac3/core/client/base_movable.lua
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,10 @@ function PART:CalcAngles(ang, wpos)
local nearest_ent = part:GetRootPart():GetOwner()
local nearest_dist = math.huge
local owner_ent = part:GetRootPart():GetOwner()
local part_pos = part:GetWorldPosition()

for _,ent in pairs(ents.FindInSphere(part_pos, 5000)) do
for _,ent in pairs(ents.FindInSphere(wpos, 5000)) do
if (ent:IsNPC() or ent:IsPlayer()) and ent ~= owner_ent then
local dist = (owner_ent:GetPos() - ent:GetPos()):LengthSqr()
local dist = (wpos - ent:GetPos()):LengthSqr()
if dist < nearest_dist then
nearest_ent = ent
nearest_dist = dist
Expand All @@ -211,18 +210,18 @@ function PART:CalcAngles(ang, wpos)

if pac.StringFind(self.AimPartName, "NEAREST_LIFE_YAW", true, true) then
local nearest_ent = get_nearest_ent(self)
local ang = (nearest_ent:GetPos() - self:GetWorldPosition()):Angle()
local ang = (nearest_ent:GetPos() - wpos):Angle()
return Angle(0,ang.y,0) + self.Angles
end

if pac.StringFind(self.AimPartName, "NEAREST_LIFE_POS", true, true) then
local nearest_ent = get_nearest_ent(self)
return self.Angles + (nearest_ent:GetPos() - self:GetWorldPosition()):Angle()
return self.Angles + (nearest_ent:GetPos() - wpos):Angle()
end

if pac.StringFind(self.AimPartName, "NEAREST_LIFE", true, true) then
local nearest_ent = get_nearest_ent(self)
return self.Angles + ( nearest_ent:GetPos() + Vector(0,0,(nearest_ent:WorldSpaceCenter() - nearest_ent:GetPos()).z * 1.5) - self:GetWorldPosition()):Angle()
return self.Angles + ( nearest_ent:GetPos() + Vector(0,0,(nearest_ent:WorldSpaceCenter() - nearest_ent:GetPos()).z * 1.5) - wpos):Angle()
end

if self.AimPart:IsValid() and self.AimPart.GetWorldPosition then
Expand Down

0 comments on commit 4fb95a8

Please sign in to comment.