Hi there! My problem is that I want to make a Free Camera Movement with in a Region3 Box, (like The Game Bloxburg).
I have got the code to move the camera, but I am unsure on how to actually control the Movement of the camera with-in that Box.
Here is what I have got so far: (Make sure to read after this script)
-- Creating the "Region3"
local point1 = game.Workspace.Point1
local point2 = game.Workspace.Point2
local region = Region3.new(point1.Position,point2.Position)
-- To show the "Region3" in-game
local p = Instance.new("Part",workspace)
p.Anchored = true
p.CanCollide = false
p.Transparency = 0.8
p.Size = region.Size
p.CFrame = region.CFrame
--- Camera Movement
local RunService = game:GetService("RunService")
local UserInputService = game:GetService("UserInputService")
local TweenService = game:GetService("TweenService")
local camera = workspace.CurrentCamera
camera.CameraType = Enum.CameraType.Scriptable
local x = 0
local y = 12
local angle = Instance.new("CFrameValue")
local position = Vector3.new()
local nVec = {
[Enum.KeyCode.A] = Vector3.new(-1, 0, 0),
[Enum.KeyCode.D] = Vector3.new(1, 0, 0),
[Enum.KeyCode.S] = Vector3.new(0, 0, 1),
[Enum.KeyCode.W] = Vector3.new(0, 0, -1),
[Enum.KeyCode.Q] = Vector3.new(0, -1, 0),
[Enum.KeyCode.E] = Vector3.new(0, 1, 0)
}
local Vec = {}
local speed = 1
UISTable = {}
function UISTable.InputBegan(input)
if nVec[input.KeyCode] then
Vec[input.KeyCode] = nVec[input.KeyCode]
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
elseif input.KeyCode == Enum.KeyCode.LeftShift then
speed = 0.1
end
end
function UISTable.InputChanged(input)
if input.UserInputType == Enum.UserInputType.MouseMovement then
x = (x - math.rad(input.Delta.X))%(2*math.pi)
y = math.clamp(y - math.rad(input.Delta.Y), math.rad(-89), math.rad(89))
TweenService:Create(
angle,
TweenInfo.new(
0.01,
Enum.EasingStyle.Quad,
Enum.EasingDirection.Out,
0,
false,
0
),
{Value = CFrame.Angles(0, x, 0) * CFrame.Angles(y, 0, 0)}
):Play()
elseif input.UserInputType == Enum.UserInputType.MouseWheel then
position = position + angle.Value * Vector3.new(0, 0, 5*input.Position.Z)
end
end
function UISTable.InputEnded(input)
if nVec[input.KeyCode] then
Vec[input.KeyCode] = nil
elseif input.UserInputType == Enum.UserInputType.MouseButton2 then
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
elseif input.KeyCode == Enum.KeyCode.LeftShift then
speed = 1
end
end
for k, fn in pairs(UISTable) do
UserInputService[k]:Connect(fn)
end
local function DefaultCam(dt)
local move = Vector3.new()
for _, v in pairs(Vec) do
move = move + v
end
camera.CFrame = angle.Value + position
position = position + angle.Value * (move * speed)
end
RunService:BindToRenderStep("DefaultCam", Enum.RenderPriority.Camera.Value, DefaultCam)
Does anyone know how I should integrate the Movement Control of the Camera with in that "Region3"?
Thank you, and have a Great Day! ????
If you don't quite understand my question, then just Ask me for an Animation or something that will help you to understand.

1 comment
Oh ya, I am glad that ultraw gave me his code, its pretty helpful, it creates boundaries...