✓ Accepted answer
In order to achieve that you can use something called 'TweenService' which does smooth transitioning between anything really. It's a very neat service ROBLOX has. You can use TweenService on things such as:
A number
A bool value
A CFrame
A Rect
A Color3
A UDim
A UDim2
A Vector2
A Vector2int16
A Vector3
More on TweenService
The second thing we will use is the property of the player's camera called 'FieldOfView' which "sets how many degrees in the vertical direction (y-axis) the camera can view. Uniform scaling is enforced meaning the vertical and horizontal field of view are always related by the aspect ratio of the screen. This means the FieldOfView property also determines the horizontal field of view".
More on this here.
This FieldOfView property, when modified, will give the illusion of zooming out/in.
I was bored so I did most of the work for you:
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local tweenInfo = TweenInfo.new(
0.5,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false
)
local LocalPlayer = Players.LocalPlayer
repeat wait() until LocalPlayer.Character
local Camera = workspace.CurrentCamera
local shiftDown = false
UserInputService.InputBegan:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard and not gameProcessed then
if input.KeyCode == Enum.KeyCode.LeftShift then
shiftDown = true
local goal = {FieldOfView = 100}
local tween = TweenService:Create(Camera, tweenInfo, goal)
tween:Play()
end
end
end)
UserInputService.InputEnded:Connect(function(input, gameProcessed)
if input.UserInputType == Enum.UserInputType.Keyboard then
if input.KeyCode == Enum.KeyCode.LeftShift then
shiftDown = false
local goal = {FieldOfView = 70}
local tween = TweenService:Create(Camera, tweenInfo, goal)
tween:Play()
end
end
end)
Fun fact: The default camera FieldOfView is 70
Anyways hope I helped, please let me know if you have further questions!
1 comment
Thanks for the detailed answer! I will make sure to use this.