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.

https://gyazo.com/aeefa771699a3cdb24993b00d06f475f

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: TweenService | Documentation - Roblox Creator Hub

Oh, Got it!
But I got a problem
https://gyazo.com/313ba43e0302007cf3300ee291bdc758
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