How do I make a camera smoothly zoom in?

I am making a shooter and when the person right clicks, the camera moves from 6 studs away to 3 studs from the player. (Just zooms in.) I do this simply by changing the maxviewdistance. However, It moves the camera instantly. When the player stops right clicking to zoom in, I change the view distance back to 6 which actually does move smoothly. How would I get it to go smoothly when they initially zoom in?

2 Likes

I’ve written a simple function for you, it should work. Just pass in the value you want the FOV to be set to, along with the speed of the tween. :slight_smile:

local camera = workspace.CurrentCamera
local tween_service = game:GetService("TweenService")

local function Tween_FOV(value, speed)
     local tween_info = TweenInfo.new(speed, Enum.EasingStyle.Linear, Enum.EasingDirection.Out)
     local tween = tween_service:Create(camera, tween_info, {FieldOfView = value})
     tween:Play()
end
2 Likes

Thanks although I am not using FieldOfView. I am using the distance between the player and the camera. So when they are playing the distance the camera is from them is 6 studs away, and then when they zoom in its now 3 studs away. I use the cameraviewdistances to do it but it doesn’t zoom in smoothly.

So in that case change ā€˜camera’ to the LocalPlayer where I create the new tween object, then change ā€œFieldOfViewā€ in the table to ā€œCameraViewDistanceā€ (or the correct name of the property of Player)

I’m not entirely sure if TweenService supports that property, but it’s definitely worth a shot.

3 Likes