Smooth Camera Zoom

Hello!
I made an ADS (Aim down the sights) system.
And I wanna make a camera zoom, not like just changing the field of view, I wanna make it smooth zooming.

Here the current code:

Code
		for i = 1, module.ADS_RANGE do
			local cam = workspace.CurrentCamera
			cam.FieldOfView = (70 - (i * 2))
		end

ADS_RANGE Is 10

1 Like

Heres an example code with TweenService:

local TweenService = game:GetService("TweenService")

local tweenInfo = TweenInfo.new(
    0.2, -- Time
    Enum.EasingStyle.Linear, -- EasingStyle
    Enum.EasingDirection.Out, -- EasingDirection
    -1, -- RepeatCount (when less than zero the tween will loop indefinitely)
    false, -- Reverses (tween will not reverse once reaching it's goal)
    0 -- DelayTime
)

local tween = TweenService:Create(cam, tweenInfo, { FieldOfView = 70 - (module.ADS_RANGE * 2) })

tween:Play()

You can find out TweenService here.

4 Likes

Can I have some explanations?
Like
Why FieldOfView - (module.ADS_RANGE * 2)

Also, how do i make it tween back?

If you check TweenService’s wiki page you can see that it requires 3 arguments to create the tween Instance, TweenInfo and PropertyTable.

PropertyTable argument is actually a table that has the things to do, for this example if you set { FieldOfView = 1 } it will move the Camera’s FieldOfView to 1 smoothly.

You can find out more here: https://developer.roblox.com/en-us/api-reference/class/TweenService

Oh, Got it!
But I got a problem

And another thing to ask.
How do I make it tween back?

local AIM_FALSE = service:Create(workspace.CurrentCamera, ADS_FALSE, {FieldOfView = 70})

Oh, i fixed it!!
Thanks for helping.

1 Like