Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do i Transition FieldOfView correctly?

Asked by 5 years ago

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?

0
when you mean you don't want decimals, do you mean you want the FieldOfView to change by integer increments? SerpentineKing 3885 — 5y
0
Yep, like that :p Igoralexeymarengobr 365 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

1
Thank ya dude :D Igoralexeymarengobr 365 — 5y
0
This helps a lot! Igoralexeymarengobr 365 — 5y
0
No problem, happy to help! SerpentineKing 3885 — 5y
Ad

Answer this question