Skip to content

Commit 6798f68

Browse files
committed
Better physgun rotation clamp
1 parent 7c2242b commit 6798f68

1 file changed

Lines changed: 22 additions & 0 deletions

File tree

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
if SERVER then
2+
local function SnapTo(Value, SnapAngles)
3+
return math.Round(Value / SnapAngles) * SnapAngles
4+
end
5+
6+
hook.Add("OnPhysgunFreeze", "PA_FixPhysgunRotationInaccuracy", function(_, PhysObj, _, Player)
7+
if not Player:KeyDown(IN_SPEED) then return end
8+
local ShouldSnap = Player:GetInfo("precision_align_snap_physgun")
9+
if ShouldSnap == 0 then return end
10+
11+
local SnapAngles = Player:GetInfo("gm_snapangles")
12+
local Angles = PhysObj:GetAngles()
13+
local P, Y, R = Angles:Unpack()
14+
P = SnapTo(P, SnapAngles)
15+
Y = SnapTo(Y, SnapAngles)
16+
R = SnapTo(R, SnapAngles)
17+
Angles:SetUnpacked(P, Y, R)
18+
PhysObj:SetAngles(Angles)
19+
end)
20+
else
21+
CreateClientConVar("precision_align_snap_physgun", "1", true, true, "When enabled, this forces physgun snapping to always be 100% accurate to your desired gm_snapangles.", 0, 1)
22+
end

0 commit comments

Comments
 (0)