Making fov zoom out alot

I am trying to make a script that will slide the fov up a lot after a button is clicked to make a teleporting type effect, how do I go about this?

1 Like

Don’t know what you mean by a teleporting effect or exactly what you need, but you can use

game.Workspace.CurrentCamera.FieldOfView = game.Workspace.CurrentCamera.FieldOfView+30

if you would like it instantly. If you would like it to be smooth I would use a lerp function. If you would like info on how then reply.

this would be a simple loop …

local fovMultiplier = 0.99
local timeIncrement = 0.1
local numIterations = 50 

for i = 1, numIterations do
    camera.FieldOfView = camera.FieldOfView * fovMultiplier
    task.wait(timeIncrement)
end

using a for next we can control the timing and length of the effect

Assuming you want a smooth transition, you could use tweens to ease the camera into the new FOV:

local targetFOV = 90

local easingDuration = 0.5
local easingStyle = Enum.EasingStyle.Quad
local easingDirection = Enum.EasingDirection.Out

local tween = game.TweenService:Create(workspace.CurrentCamera, TweenInfo.new(easingDuration, easingStyle, easingDirection), {
    FieldOfView = targetFOV
})
tween:Play()

You could put this inside of a button activated callback to make it happen when a button is pressed, though you should also probably include a debounce.

button.Activated:Connect(function()
    -- Put the above tweening code here.
end)

You can adjust the speed and style of the easing by adjusting the easingDuration, easingStyle and easingDirection variables. This also has the benefit of being much more readable to other solutions, even though it has it’s downsides.

1 Like

Thank you this is what I was looking for, my current script was very jumbled and over complicated

1 Like

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