Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i Transition FieldOfView correctly?

I've been trying to lerp CurrentCamera.FieldOfView from 70 to 100, but nothing i have found helped me, Lerp,Tween,Interpolate, i can't figure out what i am doing wrong, this is the base script:

repeat wait() until workspace.CurrentCamera
local cam = workspace.CurrentCamera
local fov = cam.FieldOfView
DefaultFov = 70
MaxFov = 100

I want to figure out how to interpolate those values from 70 to 100 without returning any value like 70.8, 79.06,etc... Is there a correct way to do that?

2 comments

0

when you mean you don't want decimals, do you mean you want the FieldOfView to change by integer increments?

0

Yep, like that :p

1 answer

✓ Accepted answer

Ok, so firstly, the camera's FieldOfView is a float meaning it will likely never be exactly an integer: https://developer.roblox.com/api-reference/property/Camera/FieldOfView

However, you can alter the FieldOfView by integer increments using a for-loop.

Revised Local Script Example

repeat wait() until workspace.CurrentCamera ~= nil
local cam = workspace.CurrentCamera

for f = 70, 100, 1 do
	cam.FieldOfView = f
	wait()
end

If you need to print an integer or have a function that requires the value of FOV to be an integer, you can use the functions math.floor() -- Round Down, or math.ceil() -- Round Up on the FieldOf View in your code.

print(math.floor(cam.FieldOfView))

print(math.ceil(cam.FieldOfView))

If you need to make sure the value of FieldOfView cannot surpass 100, you can also use these functions, or use math.clamp() as is explained in the link below.

https://developer.roblox.com/articles/Lua-Libraries/math

3 comments

1

Thank ya dude :D

0

This helps a lot!

0

No problem, happy to help!

This discussion is preserved as it was. New answers, comments, and votes are closed.