Hello. I have a camera freemove script, that allows you to move around with the camera with the keys WASD, and I was wondering how to add boundaries to it. The camera is used inside a building function to be able to easily build on your plot, and I don’t want the player to be able to pan their camera anywhere in the world. I am not very good at camera manipulation so I’m pretty much lost when it comes to adding a boundary system (one that doesn’t jitter the camera back and forth once you reach the edges). ANybody got any ideas?
Heres my camera freemove script
local run = game:GetService("RunService")
local uis = game:GetService("UserInputService")
repeat wait() until workspace.CurrentCamera
local cam = game.Workspace.CurrentCamera
local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local movementSpeed = 80
local moveForce = 900
local velocity = Vector3.zero
local startCamera = game.ReplicatedStorage.Remotes:WaitForChild("Camera")
local function inputs()
local direction = Vector3.zero
if uis:IsKeyDown(Enum.KeyCode.A) then
direction += Vector3.xAxis
end
if uis:IsKeyDown(Enum.KeyCode.D) then
direction -= Vector3.xAxis
end
if uis:IsKeyDown(Enum.KeyCode.W) then
direction += Vector3.zAxis
end
if uis:IsKeyDown(Enum.KeyCode.S) then
direction -= Vector3.zAxis
end
if direction ~= Vector3.zero then
direction = direction.Unit
end
print(direction)
return direction
end
local function clamp(v, min, max)
return v.Unit * math.clamp(v.Magnitude, min, max)
end
local function cameraMovement(dt)
local direction = inputs()
if direction ~= Vector3.zero then
velocity += moveForce * direction * dt
velocity = clamp(velocity, 0, movementSpeed)
print(cam.CFrame)
else
velocity *= math.clamp(1 - (15 * dt), 0, 1_)
end
cam.CFrame += velocity * dt
end
local function updateCam(dt)
cameraMovement(dt)
end
local connection
startCamera.Event:Connect(function(status, plot)
if status == true then
cam.CFrame = plot.Assets.Grid.CFrame * (CFrame.new(0, 90, 0) * CFrame.Angles(math.rad(45), -math.rad(180), 0))
cam.CameraSubject = plot.Assets.Grid
cam.CameraType = Enum.CameraType.Scriptable
connection = run.RenderStepped:Connect(cameraMovement)
else
cam.CFrame = player.Character.HumanoidRootPart.CFrame
cam.CameraSubject = player.Character.Humanoid
cam.CameraType = Enum.CameraType.Custom
connection:Disconnect()
connection = nil
end
end)