Dynamic Field of View

They (at least CFrame, position and orientation) don’t fire when they’re updated via physics, it’ll fire if you manually write to part.CFrame/part.Position etc

Probably Heartbeat would be better, since it fires after the physics frame.
EDIT: Heartbeat, not PostSimulation. Not sure what PostSimulation is there doesn’t seem to be any information regarding it.

1 Like

I tried this but it didn’t work. No errors in the output, just simply does not work.

Edit: I tried using print statements and it works as expected all until the function.

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
print('Player added.')

local camera = workspace.CurrentCamera
print('Acquired camera.')

local max = 120
local min = 70
local dampen = 10
print('Set locales.')

char.PrimaryPart:GetPropertyChangedSignal("Velocity"):Connect(function()
	print('Detected.')
	camera.FieldOfView = math.clamp(70 + char.PrimaryPart.Velocity.Magnitude/dampen,min,max) -- tweak around with dampen to increase/decrease the linear change in fov
	print('Changed Field of View.')
end)

Just ends after print('Set locales.')

So do as the others have suggested and instead of a function that waits for a property changed signal, use a Heartbeat loop that gets the Velocity each frame of the game playing.

Sorry if this is annoying lool but how do I get the velocity of each frame?? I’m decent at scripting, just RunService and velocity are one of my 2 weaknesses.

Something like this:

local RunService = game:GetService("RunService")

function calculateFov()
    camera.FieldOfView = math.clamp(70 + char.PrimaryPart.Velocity.Magnitude/dampen,min,max) -- tweak around with dampen to increase/decrease the linear change in fov
end

RunService.Heartbeat:Connect(calculateFov)
2 Likes

Works like a charm now, thanks so much!

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.