How to add camera zoom for mobile?

i will try to keep it simple;

i have a topdown camera system, it sets your camera position to a set heigh from your humanoidrootpart, i also have events for mouse wheel movement to change its zoom amount on computers, but majority of my players are mobile and they want to zoom in/out too.

so, how can i detect two finger closing and two finger opening movement of mobile players and make them able to zoom too.

here is the script i use, it would be really appreciated if you added mobile support to it and send back the script, i promise i will be able to understand it from the documents.

 local camera = game.Workspace:WaitForChild("Camera")

local char:Model = script.Parent
local hrp = char.HumanoidRootPart

local mouse = game.Players.LocalPlayer:GetMouse()

local distance = 135

local minDistance = 100
local maxDistance = 170

local RunService = game:GetService("RunService")

camera.CameraType = Enum.CameraType.Scriptable
RunService.RenderStepped:Connect(function()
	camera.CFrame = CFrame.new(hrp.Position + (hrp.CFrame.UpVector * distance)) * CFrame.Angles(math.rad(-90),0,0)
end)

mouse.WheelForward:Connect(function()
	if distance >= minDistance then
		distance -= 5
	end
end)
mouse.WheelBackward:Connect(function()
	if distance <= maxDistance then
		distance += 5
	end
end)
2 Likes

i just archived the game instead of adding mobile support :smiley:

1 Like