From 447bb603c18fb4eac06cbe13dc2adb140179e12d Mon Sep 17 00:00:00 2001 From: Fesiug Date: Sun, 22 Oct 2023 00:38:30 -0400 Subject: [PATCH] Shared shoulder cam offset, better movement --- .../gamemode/modules/player/cl_camera.lua | 12 +----- .../gamemode/modules/player/sh_inventory.lua | 29 +++++++++++++ .../gamemode/modules/player/sh_movement.lua | 42 +++++++++++-------- 3 files changed, 55 insertions(+), 28 deletions(-) diff --git a/gamemodes/benny/gamemode/modules/player/cl_camera.lua b/gamemodes/benny/gamemode/modules/player/cl_camera.lua index 084104d..d35bb1a 100644 --- a/gamemodes/benny/gamemode/modules/player/cl_camera.lua +++ b/gamemodes/benny/gamemode/modules/player/cl_camera.lua @@ -269,17 +269,7 @@ function bennyfp( origin, angles, fov ) local ply = LocalPlayer() if !IsValid( ply:GetActiveWeapon() ) then return origin, angles, fov end - local pos, ang = Vector(), Angle() - - pos:Set( ply:GetPos() ) - pos.z = pos.z + 64 - ang:Set( TPSOverride ) - - pos:Add( 16 * ang:Right() ) - pos:Add( -32 * ang:Forward() ) - pos:Add( 0 * ang:Up() ) - - pos:Add( 16 * ang:Up() * (ang.p/90) ) + local pos, ang = ply:CamSpot( TPSOverride ) return pos, ang, 90 end diff --git a/gamemodes/benny/gamemode/modules/player/sh_inventory.lua b/gamemodes/benny/gamemode/modules/player/sh_inventory.lua index 5b2a08d..d5f162b 100644 --- a/gamemodes/benny/gamemode/modules/player/sh_inventory.lua +++ b/gamemodes/benny/gamemode/modules/player/sh_inventory.lua @@ -1,6 +1,35 @@ local PT = FindMetaTable( "Player" ) +function PT:CamSpot( ang ) + local w = self:GetActiveWeapon() + if !IsValid( w ) then w = false end + + local aim = w and w:GetAim() or 0 + aim = w:GetUserAim() and math.ease.OutCubic( aim ) or math.ease.InCubic( aim ) + + local pos = self:GetPos() + + local perc = math.TimeFraction( self:GetViewOffset().z, self:GetViewOffsetDucked().z, self:GetCurrentViewOffset().z ) + pos.z = pos.z + Lerp( perc, 64, 52 ) + + pos:Add( Lerp( aim, 16, 16 ) * ang:Right() ) + pos:Add( Lerp( aim, -64, -32 ) * ang:Forward() ) + pos:Add( 0 * ang:Up() ) + + pos:Add( Lerp( aim, 16, 16 ) * ang:Up() * (ang.p/90) ) + + local tr = util.TraceHull( { + start = self:GetPos() + Vector( 0, 0, Lerp( perc, 64, 52 ) ), + endpos = pos, + mins = -Vector( 4, 4, 4 ), + maxs = Vector( 4, 4, 4 ), + filter = self + }) + + return tr.HitPos, ang, 90 +end + function PT:INV_Get() if !self.INV then print( "Inventory created") diff --git a/gamemodes/benny/gamemode/modules/player/sh_movement.lua b/gamemodes/benny/gamemode/modules/player/sh_movement.lua index 320ec66..8348c16 100644 --- a/gamemodes/benny/gamemode/modules/player/sh_movement.lua +++ b/gamemodes/benny/gamemode/modules/player/sh_movement.lua @@ -4,7 +4,8 @@ local wa, wb = 0, 0 local blop = Angle() -TPSOverride = Angle() +local lastmoveangle = 0 +TPSOverride = TPSOverride or Angle() hook.Add( "CreateMove", "CamFuck", function( cmd ) if false and BENNY_ACTIVECAMERA and LocalPlayer():GetMoveType() != MOVETYPE_NOCLIP then local x, y = cmd:GetForwardMove(), cmd:GetSideMove() @@ -54,36 +55,43 @@ hook.Add( "CreateMove", "CamFuck", function( cmd ) if true and LocalPlayer():GetMoveType() != MOVETYPE_NOCLIP then -- FPS cam local p = LocalPlayer() + local w = p:GetActiveWeapon() + if !IsValid(w) then w = false end + local aimed = w and w:GetUserAim() - local opos, ang = p:EyePos(), TPSOverride + local opos, ang = p:CamSpot( TPSOverride ) ang:Add( Angle( cmd:GetMouseY()*0.022, -cmd:GetMouseX()*0.022, 0 ) ) ang:Normalize() - -- PROTO: These and the values in CalcView should use a common function - -- to get their position, and to allow easy shoulder switching or overhead. - opos:Add( 16 * ang:Right() ) - opos:Add( -32 * ang:Forward() ) - opos:Add( 0 * ang:Up() ) - opos:Add( 16 * ang:Up() * (ang.p/90) ) - local tr = util.TraceLine( { - start = opos, - endpos = opos+(ang:Forward()*(2^16)), - filter = p, - mask = MASK_SOLID, - } ) + if aimed then + local tr = util.TraceLine( { + start = opos, + endpos = opos+(ang:Forward()*(2^16)), + filter = p, + mask = MASK_SOLID, + } ) - local planner = (tr.HitPos-p:EyePos()):Angle() - planner:Normalize() + local planner = (tr.HitPos-p:EyePos()):Angle() + planner:Normalize() + cmd:SetViewAngles( planner ) + lastmoveangle = planner.y + end local moveintent = Vector( cmd:GetForwardMove(), cmd:GetSideMove(), 0 ) + if !aimed then + if !moveintent:IsEqualTol( vector_origin, 1 ) then + lastmoveangle = ang.y - moveintent:Angle().y + end + cmd:SetViewAngles( Angle( ang.p, lastmoveangle, 0 )) + end + local fixang = Angle() fixang.y = cmd:GetViewAngles().y - ang.y moveintent:Rotate( fixang ) - cmd:SetViewAngles( planner ) cmd:ClearMovement() cmd:SetForwardMove( moveintent.x )