Help with camera

I can’t zoom out. That’s the only problem but I don’t know how to fix it

local rotation = Vector2.new()

local SHIFTLOCKCAM = RS.RenderStepped:Connect(function()
	local delta = UIS:GetMouseDelta()
	rotation = rotation + Vector2.new(-delta.Y, -delta.X)
	local cameraOffset = CFrame.new(2.2, 0, 3)

	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)

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

EDIT: added clamping

1 Like

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)

1 Like

Honestly, it would be better to just add a event that is in the playermodule that you can call to enable shiftlock

1 Like