Hello developers, i am currently working on a few things, and one of them is basically a cam that moves by dragging the mouse, everything works fine so far, but i’m struggling with putting a limit so when it reaches a certain point, it stops moving.
Is there any way to do that? If so, your help would be appreciated
Here’s the script:
local run = game:GetService'RunService'
local uis = game:GetService'UserInputService'
local plr = game.Players.LocalPlayer
local mouse = plr:GetMouse()
local cam = workspace.CurrentCamera
local speed = 3 -- Speed when dragging
local lockMouse = true -- locks mouse when dragging
local origin = CFrame.lookAt(Vector3.new(0,1000,0), Vector3.new()) -- Where the camera will start
local moved = Vector2.zero -- How much the camera has moved
local dragging = false
local oldMousePos = Vector2.zero
mouse.Button1Down:Connect(function()
dragging = true
oldMousePos = uis:GetMouseLocation()
end)
mouse.Button1Up:Connect(function()
dragging = false
uis.MouseBehavior = Enum.MouseBehavior.Default
end)
run.RenderStepped:Connect(function(dt)
if dragging then
if lockMouse then
uis.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
moved += uis:GetMouseDelta()*speed*dt
else
moved += (uis:GetMouseLocation() - oldMousePos)*speed*dt
oldMousePos = uis:GetMouseLocation()
end
end
cam.CFrame = origin * CFrame.new(-moved.X*speed, moved.Y*speed, 0)
end)
And here’s a video of how it works:
Also as an extra, if you could, is it possible to zoom in and out with the scroll of the mouse?
Greetings Nico.