Adjust Viewmodel According to FOV

I’m making an FPS game in Roblox, and when I change the camera’s FOV (like from 75 to 120), the weapon viewmodel shrinks or looks pushed back.

I want to compensate the viewmodel position so it always looks the same size on screen, no matter the FOV.

Here’s a minimal test script:

local RunService = game:GetService("RunService")
local camera = workspace.CurrentCamera
local viewmodel = script["AR-15"]:Clone()
viewmodel.Parent = camera

RunService.RenderStepped:Connect(function()
	viewmodel:PivotTo(camera.CFrame)
end)

What’s the correct formula or code to fix this? Should I adjust only the Z axis (depth) or also X/Y?

Any help is appreciated! Thank you

2 Likes

You are basically wanting to replicate effect from game “Super liminal” search it up people had already made tutorials on that in devforum.
Also consider using .PreRender as since RenderStepped is depracated.

RenderStepped isn’t deprecated yet, but it is still advised to use PreRender instead. Also it is important to note that BindToRenderStep uses PreRender ( if ya didn’t know :wink: )

1 Like

I think there’s been a misunderstanding, my issue isn’t related to “Super liminal” perspective effect.
What I need is to keep the Viewmodel the same apparent size on screen, even when the player changes the camera FOV (ex: from 75 to 120).

If anyone knows how to solve this, I’d really appreciate it!

1 Like

Here’s something that worked for me:

self.GunModel:PivotTo(Camera.CFrame * targetCFrame * CFrame.new(0, 0, (Camera.FieldOfView - 70) / 35))

Only focus on the last part:

CFrame.new(0, 0, (Camera.FieldOfView - 70) / 35) -- replace default 70 with default FOV, and replace 35 with default FOV / 2

See if that works.