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
.
01 | local cam = game.Workspace.CurrentCamera |
02 | local mouse = game.Players.LocalPlayer:GetMouse() |
03 | local TweenService = game:GetService( "TweenService" ) |
04 | local debounce = false |
05 | local aiming = false |
06 | local t = . 3 |
07 |
08 | local info = TweenInfo.new(t, Enum.EasingStyle.Linear,Enum.EasingDirection.In, 0 , false , 0 ) --(time,easingStyle,EasingDirection,NumberOfRepeats,canRepeat,delay) |
09 |
10 | local Forward = { FieldOfView = 60 } -- change right side of equation to whatever |
11 | local Backward = { FieldOfView = 70 } |
12 |
13 | local zoomIn = TweenService:Create(cam,info,Forward) -- these create the tweens |
14 | local zoomOut = TweenService:Create(cam,info,Backward) |
15 |
Look up tweening if you want to learn more. Also, don't forget to mark this as the answer!