Make the camera move only on the X axis

Basically I want to make something that doesn’t allow the player to move the camera on the Y and Z axis for example.

Is there any way to do it?

I didn’t find anything on the forum so I created a topic
Please help!!!

2 Likes

in StarterPlayer → StarterCharacterScripts create local script and paste this:

local Players = game:GetService("Players").LocalPlayer
local char = script.Parent
local hrp = char:WaitForChild("HumanoidRootPart")
local cam = workspace.CurrentCamera
cam.CameraType = Enum.CameraType.Scriptable

--folder for camera
local PlayerCamera = Instance.new("Folder")
PlayerCamera.Parent = workspace
PlayerCamera.Name = "PlayerCamera"

--camera
local cameraPart = Instance.new("Part")
cameraPart.Transparency = 1
cameraPart.CanCollide = false
cameraPart.Parent = workspace.PlayerCamera
cameraPart.CFrame = CFrame.new(hrp.Position + Vector3.new(-30,10,0), hrp.Position) -->camera angle

--camera move
local bp = Instance.new("BodyPosition")
bp.MaxForce = Vector3.new(math.huge, math.huge, math.huge)
bp.P = 100000 --> camera speed
bp.Parent = cameraPart

--loop
game:GetService("RunService").RenderStepped:Connect(function()
	

	bp.Position = hrp.Position + Vector3.new(-20, 6, 0) --> X = approach, Y = up down, Z = left right,
	cam.CFrame = cameraPart.CFrame
end)
1 Like

Thanks but the camera doesn’t follow the player movements, I’ll give you an example:

camera

It should look like this, the player can’t look up or down

To do this, you have to set the camera’s Y-axis to the target, then make it face towards the target.
Here’s a line of code that should help you with doing this.

    -- The root is the camera subject (ie the head)
    -- The rest is self-explanatory
   
    -- Why multiply by Vector3.new(1, 0, 1)? Well, what happens when you multiply any number by zero?
    -- It becomes zero. Multiplying by one does nothing.
    -- We set the Y axis to zero so that it becomes zero.
    local newCameraCFrame = CFrame.new(
        root - (cameraCFrame.LookVector * Vector3.new(1, 0, 1) * zoomOutDistance),
        root -- LookAt
    )

1 Like

Stop giving people entire scripts and not explaining what they do.

7 Likes

Apologies for necroposting, but for those who are encountering an issue with the choppy looks (i.e. the camera visibly snapping back down,) even with the solution in this topic, it is likely because you are using Hearbeat instead of Renderstepped.
For example, the code here should not be:

game["Run Service"].Heartbeat:Connect(function()
        --blah blah blah code stuff here
end)

but instead be:

game["Run Service"].RenderStepped:Connect(function()
        --blah blah blah code stuff here
end)

This drove me crazy for a good bit before finally finding it out, so I’ll post this here to prevent any future headaches for those who want to replicate the effect posted above.