In my game, I want the camera to zoom in when you aim with a gun. This is simple to do, but just changing the FOV or zoom distance values is choppy. Is there a way to smoothly do this?
Maybe use TweenService
.
local cam = game.Workspace.CurrentCamera local mouse = game.Players.LocalPlayer:GetMouse() local TweenService = game:GetService("TweenService") local debounce = false local aiming = false local t= .3 local info = TweenInfo.new(t, Enum.EasingStyle.Linear,Enum.EasingDirection.In,0,false,0) --(time,easingStyle,EasingDirection,NumberOfRepeats,canRepeat,delay) local Forward = { FieldOfView = 60 } -- change right side of equation to whatever local Backward = {FieldOfView = 70 } local zoomIn = TweenService:Create(cam,info,Forward) -- these create the tweens local zoomOut = TweenService:Create(cam,info,Backward) mouse.Button2Down:Connect(function() --change this to whatever makes the player aim if debounce == false then debounce = true zoomIn:Play() -- this plays the tween end end) mouse.Button2Up:Connect(function() if debounce == true then debounce = false zoomOut:Play() end end)
Look up tweening if you want to learn more. Also, don't forget to mark this as the answer!