Skip to content

Commit

Permalink
Bugfix: Fixed weapon FOV issues (#1508)
Browse files Browse the repository at this point in the history
  • Loading branch information
TW1STaL1CKY authored Apr 11, 2024
1 parent 273b172 commit 722cbc0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ All notable changes to TTT2 will be documented here. Inspired by [keep a changel
- Fixed detective search being overwritten by player search results
- Fixed `DynamicCamera` error when a weapon's `CalcView` doesn't return complete values (by @TW1STaL1CKY)
- Fixed Roundendscreen showing karma changes even if karma is disabled
- Fixed the player's FOV staying zoomed in if their weapon is removed while scoped in (by @TW1STaL1CKY)
- Fixed weapon unscoping (or generally any time FOV is set back to default) being delayed due to the player's lag (by @TW1STaL1CKY)

### Removed

Expand Down
26 changes: 16 additions & 10 deletions gamemodes/terrortown/entities/weapons/weapon_tttbase.lua
Original file line number Diff line number Diff line change
Expand Up @@ -769,16 +769,6 @@ if CLIENT then
-- @realm client
function SWEP:DrawWeaponSelection() end

---
-- @realm client
function SWEP:OnRemove()
local owner = self:GetOwner()

if IsValid(owner) and owner == LocalPlayer() and owner:IsTerror() then
RunConsoleCommand("lastinv")
end
end

---
-- @realm client
function SWEP:CalcViewModel()
Expand Down Expand Up @@ -1223,6 +1213,22 @@ function SWEP:Reload()
self:SetZoom(false)
end

---
-- Called when the weapon entity is about to be removed
-- @see https://wiki.facepunch.com/gmod/WEAPON:OnRemove
-- @realm shared
function SWEP:OnRemove()
if CLIENT then
local owner = self:GetOwner()

if IsValid(owner) and owner == LocalPlayer() and owner:IsTerror() then
RunConsoleCommand("lastinv")
end
end

self:SetZoom(false)
end

---
-- Called when the weapon entity is reloaded on a changelevel event
-- @see https://wiki.facepunch.com/gmod/WEAPON:OnRestore
Expand Down
24 changes: 20 additions & 4 deletions gamemodes/terrortown/gamemode/client/cl_main.lua
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,8 @@ local position = 0
local frameCount = 10

local lastStrafeValue = 0
local lastFovTimeValue = 0
local curTimeShift = 0

local cvHostTimescale = GetConVar("host_timescale")

Expand Down Expand Up @@ -867,10 +869,24 @@ function GM:DynamicCamera(viewTable, ply)

-- dynamic mode: transition between different FOV values
else
local time = math.max(
0,
(CurTime() - ply:GetFOVTime()) * game.GetTimeScale() * cvHostTimescale:GetFloat()
)
local fovTime = ply:GetFOVTime()

if lastFovTimeValue ~= fovTime then
lastFovTimeValue = fovTime
curTimeShift = 0
end

local curTime = CurTime() + curTimeShift

-- GetFOVTime ends up in the future with lag, causing a delay in the transition (the bigger your lag, the longer the delay)
-- shift curTime by the difference to correct it
if curTime < fovTime then
curTimeShift = fovTime - curTime
curTime = curTime + curTimeShift
end

local time =
math.max(0, (curTime - fovTime) * game.GetTimeScale() * cvHostTimescale:GetFloat())

local progressTransition = math.min(1.0, time / ply:GetFOVTransitionTime())

Expand Down

0 comments on commit 722cbc0

Please sign in to comment.