From 2be4facd8a266e7b11c039e40a7a28b756e17b45 Mon Sep 17 00:00:00 2001 From: Fesiug Date: Mon, 9 Oct 2023 15:11:00 -0400 Subject: [PATCH] TPS camera, point the weapon at center of screen! --- .../gamemode/modules/player/cl_camera.lua | 2 +- .../gamemode/modules/player/sh_movement.lua | 40 ++++++++++++++++++- 2 files changed, 40 insertions(+), 2 deletions(-) diff --git a/gamemodes/benny/gamemode/modules/player/cl_camera.lua b/gamemodes/benny/gamemode/modules/player/cl_camera.lua index 3c0fc6f..084104d 100644 --- a/gamemodes/benny/gamemode/modules/player/cl_camera.lua +++ b/gamemodes/benny/gamemode/modules/player/cl_camera.lua @@ -273,7 +273,7 @@ function bennyfp( origin, angles, fov ) pos:Set( ply:GetPos() ) pos.z = pos.z + 64 - ang:Set( angles ) + ang:Set( TPSOverride ) pos:Add( 16 * ang:Right() ) pos:Add( -32 * ang:Forward() ) diff --git a/gamemodes/benny/gamemode/modules/player/sh_movement.lua b/gamemodes/benny/gamemode/modules/player/sh_movement.lua index 1f11976..35a4784 100644 --- a/gamemodes/benny/gamemode/modules/player/sh_movement.lua +++ b/gamemodes/benny/gamemode/modules/player/sh_movement.lua @@ -4,7 +4,7 @@ local wa, wb = 0, 0 local blop = Angle() - +TPSOverride = 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() @@ -51,6 +51,44 @@ hook.Add( "CreateMove", "CamFuck", function( cmd ) cmd:SetViewAngles( blop ) end + + if true then -- FPS cam + local p = LocalPlayer() + + local opos, ang = p:EyePos(), 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, + } ) + + local planner = (tr.HitPos-p:EyePos()):Angle() + planner:Normalize() + + local moveintent = Vector( cmd:GetForwardMove(), cmd:GetSideMove(), 0 ) + + local fixang = Angle() + fixang.y = cmd:GetViewAngles().y - ang.y + moveintent:Rotate( fixang ) + + cmd:SetViewAngles( planner ) + + cmd:ClearMovement() + cmd:SetForwardMove( moveintent.x ) + cmd:SetSideMove( moveintent.y ) + end end) function GM:PlayerNoClip()