Fix weapon interpolation, fix inputs when paused

This commit is contained in:
Fesiug 2024-09-17 17:46:44 -04:00
parent 915f463b2a
commit 6701618db1
Signed by: Fesiug
GPG Key ID: 374BFF45E1EEF243
3 changed files with 49 additions and 33 deletions

View File

@ -37,23 +37,37 @@ else
end end
function ENT:PlayAnimation( seqid, speed ) function ENT:PlayAnimation( seqid, speed )
local time = self:SequenceDuration( seqid )
speed = speed or 1
self.AnimStartTime = ( UnPredictedCurTime() )
self.AnimEndTime = ( UnPredictedCurTime() + time )
self:SetAnimStartTime( self.AnimStartTime )
self:SetAnimEndTime( self.AnimEndTime )
self:ResetSequence( seqid ) self:ResetSequence( seqid )
-- Interpolation
if CLIENT and IsFirstTimePredicted() then
self.CLCycle = 0
self.StartTime = UnPredictedCurTime()
end
end end
function ENT:Think() function ENT:Think()
self:NextThink( CurTime()-5 )
if false and SERVER then
print( "m_flAnimTime", self:GetInternalVariable("m_flAnimTime") )
print( "m_flPrevAnimTime", self:GetInternalVariable("m_flPrevAnimTime") )
print( "m_bClientSideAnimation", self:GetInternalVariable("m_bClientSideAnimation") )
print( "m_bClientSideFrameReset", self:GetInternalVariable("m_bClientSideFrameReset") )
print( "cycle", self:GetInternalVariable("cycle") )
end
self:NextThink( CurTime() )
if CLIENT then if CLIENT then
self:SetNextClientThink( CurTime()-5 ) self:SetNextClientThink( CurTime()-5 )
-- Smooth interpolated shooting on local player
-- Interpolation
if self:GetOwner() == LocalPlayer() then if self:GetOwner() == LocalPlayer() then
local cycle = math.Remap( UnPredictedCurTime(), self.AnimStartTime or 0, self.AnimEndTime or 0, 0, 1 ) local diff = (UnPredictedCurTime()) - (self.LastThink or UnPredictedCurTime())
self:SetCycle( cycle )
if diff then
self.CLCycle = math.Approach( self.CLCycle or 0, 1, ( 1/self:SequenceDuration() ) * diff )
self:SetCycle( self.CLCycle )
self.LastThink = UnPredictedCurTime()
end
end end
end end

View File

@ -4,7 +4,7 @@ AddCSLuaFile()
SWEP.Base = "weapon_base" SWEP.Base = "weapon_base"
SWEP.BennyItemHandler = true SWEP.BennyItemHandler = true
SWEP.ViewModel = "models/weapons/c_arms.mdl" SWEP.ViewModel = "models/weapons/c_pistol.mdl"
SWEP.ViewModelFOV = 74 SWEP.ViewModelFOV = 74
SWEP.ViewModelFlip = false SWEP.ViewModelFlip = false
SWEP.UseHands = true SWEP.UseHands = true
@ -144,8 +144,8 @@ function SWEP:EquipItem( ent )
ent:SetNoDraw( true ) ent:SetNoDraw( true )
ent:SetParent( p ) ent:SetParent( p )
ent:SetOwner( p ) ent:SetOwner( p )
ent:SetPos( vector_origin ) ent:SetLocalPos( vector_origin )
ent:SetAngles( Angle( 0, p:EyeAngles().y, 0 ) ) ent:SetLocalAngles( angle_zero )
ent:SetAcquisition( CurTime() ) ent:SetAcquisition( CurTime() )
ent:EmitSound( "ae/items/pickup.ogg", 70, 100, 1, CHAN_STATIC ) ent:EmitSound( "ae/items/pickup.ogg", 70, 100, 1, CHAN_STATIC )

View File

@ -333,6 +333,7 @@ end )
if CLIENT then if CLIENT then
hook.Add("CreateMove", "Benny_CreateMove_Controls", function( cmd ) hook.Add("CreateMove", "Benny_CreateMove_Controls", function( cmd )
if !gui.IsGameUIVisible() then
if input.IsButtonDown( KEY_E ) then if input.IsButtonDown( KEY_E ) then
cmd:AddKey( IN_WEAPON1 ) cmd:AddKey( IN_WEAPON1 )
end end
@ -354,6 +355,7 @@ if CLIENT then
if input.IsButtonDown( KEY_X ) then if input.IsButtonDown( KEY_X ) then
cmd:AddKey( IN_BULLRUSH ) cmd:AddKey( IN_BULLRUSH )
end end
end
end) end)
end end