Benny/gamemodes/benny/gamemode/camera.lua

176 lines
4.8 KiB
Lua
Raw Normal View History

2024-03-07 20:34:16 -05:00
---------------------
-- Your Name is Benny
---------------------
2024-08-30 18:30:03 -04:00
local cam_f = CreateConVar( "b-cam_f", -75 )
2024-04-06 09:30:09 -04:00
local cam_r = CreateConVar( "b-cam_r", 12 )
2024-09-21 14:07:59 -04:00
local cam_u = CreateConVar( "b-cam_u", 12 )
2024-03-07 21:19:30 -05:00
local cam_fov = CreateConVar( "b-cam_fov", 75 )
2024-09-21 14:13:17 -04:00
local cam_fp = CreateConVar( "b-cam_fp", 0 )
local lastfp
2024-03-07 22:34:29 -05:00
local m = 3
2024-03-07 21:19:30 -05:00
local m2 = Vector( m, m, m )
local m1 = m2:GetNegated()
2024-04-06 09:30:09 -04:00
TPSOverride = TPSOverride or Angle( 0, 0, 0 )
2024-03-07 21:19:30 -05:00
2024-04-06 09:30:09 -04:00
function CamSpot( ang, pos )
if !ang then ang = TPSOverride end
if !pos then pos = LocalPlayer():EyePos() end
local f, r, u = TPSOverride:Forward(), TPSOverride:Right(), TPSOverride:Up()
2024-03-07 21:19:30 -05:00
local tr = {
start = pos,
endpos = pos + (f*cam_f:GetFloat()) + (r*cam_r:GetFloat()) + (u*cam_u:GetFloat()),
2024-04-07 19:04:18 -04:00
filter = LocalPlayer(), -- ply,
2024-03-07 21:19:30 -05:00
mins = m1,
maxs = m2,
}
2024-09-21 14:13:17 -04:00
if cam_fp:GetBool() then
tr.endpos = EyePos()
end
2024-03-07 21:19:30 -05:00
tr = util.TraceHull(tr)
2024-04-06 09:30:09 -04:00
return tr.HitPos
end
2024-03-07 21:19:30 -05:00
2024-04-06 09:30:09 -04:00
function GM:CalcView( ply, pos, ang, fov )
2024-03-07 20:34:16 -05:00
local view = {
2024-04-06 09:30:09 -04:00
origin = CamSpot(TPSOverride), -- pos includes the smoothstair offset which looks stupid here
angles = TPSOverride,
2024-03-07 21:19:30 -05:00
fov = cam_fov:GetFloat(),
2024-03-07 20:34:16 -05:00
drawviewer = true
}
2024-03-07 21:19:30 -05:00
2024-09-21 14:13:17 -04:00
local fp = cam_fp:GetBool()
if fp then
2024-09-06 22:53:01 -04:00
ply:SetupBones()
local bm = ply:GetBoneMatrix(ply:LookupBone("DEF-spine.006"))
view.origin = bm:GetTranslation()
2024-09-21 14:13:17 -04:00
if ply:GetLayerSequence( GESTURE_SLOT_JUMP ) == ply:LookupSequence("dive_end_handgun") then
local progress = ply:GetLayerCycle( GESTURE_SLOT_JUMP )
progress = math.TimeFraction( 0.15, 0.7, progress )
progress = math.Clamp( progress, 0, 1 )
progress = math.ease.OutCirc( progress )
local Dir = ply:GetVelocity()
Dir.z = 0
Dir:Normalize()
Dir:Rotate( Angle( 0, view.angles.y, 0 ) )
Dir:Negate()
local Addition = Angle( (progress*360), 0, 0 )
local new = Angle( view.angles )
new:Add( Addition )
view.angles = new
2024-09-06 22:53:01 -04:00
end
2024-09-21 14:13:17 -04:00
local special = math.Remap( ang.p, 0, 79, 0, 1 )
special = math.Clamp(special, 0, 1 )
special = math.ease.InCubic( special )
local special2 = math.Remap( ang.p, -79, 0, 0, 1 )
special2 = math.Clamp(special2, 0, 1 )
special2 = special2 * (1-special)
view.origin:Sub(ang:Forward()*2)
view.origin:Add(ang:Up()*4*special2)
view.origin:Add(ang:Up()*4*special)
end
2024-09-06 22:53:01 -04:00
2024-09-21 14:13:17 -04:00
if lastfp == nil then lastfp = !fp end
if lastfp and !fp then
local bid = ply:LookupBone("DEF-spine.006")
ply:ManipulateBoneScale( bid, Vector(1, 1, 1) )
local bid = ply:LookupBone("DEF-spine.005")
ply:ManipulateBoneScale( bid, Vector(1, 1, 1) )
lastfp = fp
2024-09-21 16:53:28 -04:00
-- print("show")
2024-09-21 14:13:17 -04:00
elseif !lastfp and fp then
2024-09-06 22:53:01 -04:00
local bid = ply:LookupBone("DEF-spine.006")
ply:ManipulateBoneScale( bid, vector_origin )
local bid = ply:LookupBone("DEF-spine.005")
ply:ManipulateBoneScale( bid, vector_origin )
2024-09-21 14:13:17 -04:00
lastfp = fp
2024-09-21 16:53:28 -04:00
-- print("hide")
2024-09-06 22:53:01 -04:00
end
2024-03-07 20:34:16 -05:00
return view
2024-04-06 09:30:09 -04:00
end
2024-09-21 16:53:28 -04:00
-- During a full update, bone manipulations will be reset to the server's value. Fix that
gameevent.Listen( "OnRequestFullUpdate" )
hook.Add( "OnRequestFullUpdate", "Benny_OnRequestFullUpdate_CameraFP", function( data )
if CLIENT then
local ply = LocalPlayer()
if !ply:IsValid() then return end
local fp = cam_fp:GetBool()
if lastfp == nil then lastfp = !fp end
timer.Simple( 0, function()
if !fp then
local bid = ply:LookupBone("DEF-spine.006")
if !bid then return end
ply:ManipulateBoneScale( bid, Vector(1, 1, 1) )
local bid = ply:LookupBone("DEF-spine.005")
if !bid then return end
ply:ManipulateBoneScale( bid, Vector(1, 1, 1) )
lastfp = fp
-- print("fullupdate: show")
elseif fp then
local bid = ply:LookupBone("DEF-spine.006")
if !bid then return end
ply:ManipulateBoneScale( bid, vector_origin )
local bid = ply:LookupBone("DEF-spine.005")
if !bid then return end
ply:ManipulateBoneScale( bid, vector_origin )
lastfp = fp
-- print("fullupdate: hide")
end
end)
end
end )
2024-04-06 09:30:09 -04:00
hook.Add( "InputMouseApply", "Benny_InputMouseApply", function( cmd, x, y, ang )
local p = LocalPlayer()
local w = p:HandlerCheck()
if w then--and (y!=0 or x!=0) then
if x != 0 then
TPSOverride.y = TPSOverride.y + (-x*0.022)
end
if y != 0 then
TPSOverride.p = math.Clamp( TPSOverride.p + (y*0.022), -80, 80 )
end
return true
end
end)
hook.Add("CreateMove", "Benny_CreateMove_Camera", function( cmd )
local p = LocalPlayer()
if p:GetMoveType() == MOVETYPE_NOCLIP then
cmd:SetViewAngles( TPSOverride )
else
local tr_forward = util.TraceLine( {
start = CamSpot(TPSOverride),
endpos = CamSpot(TPSOverride)+(TPSOverride:Forward()*(2^16)),
filter = p,
mask = MASK_SHOT,
} )
local planner = (tr_forward.HitPos-p:EyePos()):Angle()
planner:Normalize()
cmd:SetViewAngles( planner )
local moveintent = Vector( cmd:GetForwardMove(), cmd:GetSideMove(), 0 )
local fixang = Angle()
fixang.y = cmd:GetViewAngles().y - TPSOverride.y
moveintent:Rotate( fixang )
cmd:SetForwardMove( moveintent.x )
cmd:SetSideMove( moveintent.y )
end
end)