How can I achieve a zoom-in and a zoom-out like this?

Hello everyone,
I have a script which works like this: if the player presses “Z” the camera zooms in and the FOV decreases.

local camera = workspace.Camera
local player = game.Players.LocalPlayer
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input)

	if input.KeyCode == Enum.KeyCode.Z then

		player.CameraMode = Enum.CameraMode.Classic
		camera.FieldOfView = 15 

	end

end)

UIS.InputEnded:Connect(function(input)

	if input.KeyCode == Enum.KeyCode.Z then

		player.CameraMode = Enum.CameraMode.Classic
		camera.FieldOfView = 35 
		

	end

end)

And I also have an isometric camera:

local Players = game:GetService("Players")
local RunService = game:GetService("RunService")

local player = Players.LocalPlayer
local camera = workspace.CurrentCamera

local CAMERA_DEPTH = 64
local HEIGHT_OFFSET = 2

camera.FieldOfView = 35

local function updateCamera()
	--local character = player.Character
	if camera.CameraSubject then
		local character = camera.CameraSubject.Parent
		if character then
			local root = character:FindFirstChild("HumanoidRootPart")
			if root then
				local rootPosition = root.Position + Vector3.new(0, HEIGHT_OFFSET, 0)
				local cameraPosition = rootPosition + Vector3.new(CAMERA_DEPTH, CAMERA_DEPTH, CAMERA_DEPTH)
				camera.CFrame = CFrame.lookAt(cameraPosition, rootPosition)
			end
		end
	end
end

RunService:BindToRenderStep("IsometricCamera", Enum.RenderPriority.Camera.Value + 1, updateCamera)

And would like to have a zoom-in/zoom-out animation like the one in the first 10 seconds of this video when the player presses “Z”: (the part where it zooms in to talk with the NPC and then zooms out)

How would I be able to achieve something like this? How would I do that? Any scripts that I need?
Let me know!

Thanks in advance!

2 Likes

Are you trying to make the FieldOfView change smooth? If you are, here:

local Players = game:GetService("Players")
local Player = game.Players.LocalPlayer
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local Cam = game.Workspace.CurrentCamera

local HoldingInputKey = TweenService:Create(Cam, TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.Out), {FieldOfView = 15}) --// Feel free to adjust
local InputKeyLetGo = TweenService:Create(Cam, TweenInfo.new(0.25, Enum.EasingStyle.Quad, Enum.EasingDirection.In), {FieldOfView = 35}) --// Feel free to adjust

UserInputService.InputBegan:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Z then
		Player.CameraMode = Enum.CameraMode.Classic
		HoldingInputKey:Play()
	end
end)

UserInputService.InputEnded:Connect(function(input)
	if input.KeyCode == Enum.KeyCode.Z then
		Player.CameraMode = Enum.CameraMode.Classic
		InputKeyLetGo:Play()
	end
end)

Sorry, I can’t get it exact, that is difficult to implement as I’ve never seen anything like it.

1 Like

This is exactly what I wanted! Thank you!

1 Like

No problem, hope it helps with your development!

1 Like