I am trying to make a zero gravity space like game, but I have no idea on how to remove the camera restriction. I've looked up other stuff, but they all don't work. Please help! Thank you!
✓ ANSWER ACCEPTED
How would I remove the camera restrictions in the Y axis?
1 answer
✓ Accepted answer
Put this code in LocalScript in StarterCharacterScripts
local ContextActionService = game:GetService("ContextActionService")
local UserInputService = game:GetService("UserInputService")
local RunService = game:GetService("RunService")
local Camera = {}
function Camera.new()
local self = setmetatable(
{},
{
__index = function(self, Index)
if Camera[Index] then
return Camera[Index]
end
end
}
)
self.CurrentCamera = game.Workspace.CurrentCamera
self.Character = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait()
self.X = 0
self.Y = 0
self.Sensitivity = 0.015
self.CameraOffset = Vector3.new(0, 3, 12)
self.IsRightMouseButtonDown = false
self:Initialize()
return self
end
function Camera:Initialize()
self.CurrentCamera.CameraType = Enum.CameraType.Scriptable
ContextActionService:BindAction(
"RightClickChanged",
function(ActionName, InputState, InputObject)
self:RightClickChanged(ActionName, InputState, InputObject)
end,
false,
Enum.UserInputType.MouseButton2
)
ContextActionService:BindAction(
"UpdateAngles",
function(ActionName, InputState, InputObject)
self:UpdateAngles(ActionName, InputState, InputObject)
end,
false,
Enum.UserInputType.MouseMovement
)
RunService:BindToRenderStep("UpdateCamera", 200, function()
self:UpdateCamera()
end)
end
function Camera:RightClickChanged(ActionName, InputState, InputObject)
if InputState == Enum.UserInputState.Begin then
IsRightMouseButtonDown = true
elseif InputState == Enum.UserInputState.End then
IsRightMouseButtonDown = false
end
end
function Camera:UpdateAngles(ActionName, InputState, InputObject)
if IsRightMouseButtonDown then
UserInputService.MouseBehavior = Enum.MouseBehavior.LockCurrentPosition
self.X = self.X + (InputObject.Delta.X * -self.Sensitivity)
self.Y = self.Y + (InputObject.Delta.Y * -self.Sensitivity)
else
UserInputService.MouseBehavior = Enum.MouseBehavior.Default
end
end
function Camera:UpdateCamera()
self.CurrentCamera.CFrame = CFrame.new(self.Character.HumanoidRootPart.Position) * CFrame.fromEulerAnglesXYZ(0, self.X, 0) * CFrame.fromEulerAnglesXYZ(self.Y, 0, 0) * CFrame.new(self.CameraOffset.X, self.CameraOffset.Y, self.CameraOffset.Z)
local CameraRay = Ray.new(self.Character.HumanoidRootPart.Position, self.CurrentCamera.CFrame.Position - self.Character.HumanoidRootPart.Position)
local Ignore = {self.Character}
local HitPart, HitPosition = game.Workspace:FindPartOnRayWithIgnoreList(CameraRay, Ignore)
self.CurrentCamera.CFrame = (self.CurrentCamera.CFrame - (self.CurrentCamera.CFrame.Position - HitPosition)) + (self.Character.HumanoidRootPart.Position - self.CurrentCamera.CFrame.Position).Unit
self.CurrentCamera.Focus = self.CurrentCamera.CFrame
end
return Camera.new()
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
What do you mean by camera restrictions?
Like how to remove the restriction on the Y axis, like so I can look down and go back up, without having any restriction on the Y axis