Turn the Z axis into a variable and change it through an InputChanged event
local cameraOffset = CFrame.new(2.2, 0, zOffset) -- turn the 3 into a variable in your renderstepped
-- and add an InputChanged event that detects mouse scrolling
UserInputService.InputChanged:Connect(function(input, gpe)
if gpe or input.UserInputType ~= Enum.UserInputType.MouseWheel then
return
end
local scrolledUpwards = (input.Position.Z >= 0)
if scrolledUpwards then
zOffset += 0.5
else
zOffset -= 0.5
end
zOffset = math.clamp(zOffset, 3, 16) -- make sure it doesn't go lower than 3 or higher than 16
end)
Something like this should work ^
For controller pretty sure you can detect when the user presses the button for zooming in/out (can’t remember which one it is you’d have to look on the creator documentation), for mobile i’m unsure
Basically you can do what user (DEVLocalPlayer) above did.
Another example would be,
-- // Declared Services
local RunService = game:GetService("RunService")
local Players = game:GetService("Players");
local UserInputService = game:GetService("UserInputService");
-- // Private Variables
local Camera = workspace.CurrentCamera;
local LocalPlayer = Players.LocalPlayer;
local Mouse = LocalPlayer:GetMouse();
local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local rotation = Vector2.new()
local CurrentZoom = 0;
-- // Functions
local function ShiftLock()
local delta = UserInputService:GetMouseDelta()
rotation += Vector2.new(-delta.Y, -delta.X)
local cameraOffset = CFrame.new(2.2, 0, 3 + CurrentZoom)
Camera.CFrame = CFrame.new(Character.PrimaryPart.Position) * CFrame.Angles(0, math.rad(rotation.Y), 0) * CFrame.Angles(math.rad(rotation.X), 0, 0) * cameraOffset
end
local function Scroll(wheel)
CurrentZoom += wheel >= 0 and 1 or -1
end
-- // RBXConnections & Loops
UserInputService.PointerAction:Connect(Scroll) -- Not a good way, but this is an example.
RunService:BindToRenderStep("ShiftLockCam", Enum.RenderPriority.Character.Value + 1, ShiftLock)