How to make the camera only movable on the x, and z axis?

Alright Guys so I am making this building system pretty much just for fun maybe a future youtube tutorial but I came into a problem. The problem is I want to be able to move the camera (using my mouse) but only on the X and Z axis. I’m not sure if it’s possible (or straight forward) I have not really done much manipulating with the camera on roblox. I also couldn’t find any solutions so any help is very much appreciated.

So what I’ve tried so far is basically just setting the
camera.CameraType = Enum.CameraType.Scriptable
But that locks the camera from moving on every axis

Here’s what I have so far that locks the camera completely.

local camera = workspace.CurrentCamera

wait(0.001)

camera.CameraType = Enum.CameraType.Scriptable

wait(0.01)

camera.CFrame = game.Workspace.CamPos.CFrame

Can you elaborate on what you mean by “ only on the X and Z axis”?

Is that referring to panning? And you want the camera to behave like it does in, say, the Civilization games?

Or do you mean rotation (in which case do you actually mean “only rotate around the Y axis”)? And you want to prevent rotation up and down?

Or do you mean some combination of both?

So basically I want the normal movement of the camera just without the ability to move the camera up and down

So you want the vertical angle and distance fixed, but with the ability to rotate around the player side to side?

Yes except it wont be the player i’ll be moving around its what I am building. I already know how to disable the character controls. Just don’t know anything about the camera

Well, first I would say that if I were building something, I would want total freedom of camera movement and would be annoyed if it were constrained. But you didn’t ask about that, so…

The easiest way to handle the camera is just to have the normal control scripts run, and then patch up the position afterwards in the same frame.

You can do this cleanly by using RunService | Roblox Creator Documentation with a high priority:

game:GetService("RunService"):BindToRenderStep("FixCamera", Enum.RenderPriority.Last.Value + 1, function()
    -- patch up camera position here
end)

For this case, you’d probably want to have a hard-coded angle and distance, and set the camera to that angle and distance but rotated on the Y axis to match the current one. I can give more details on that part if you need.

Thank you so much. I’m about to try it but it looks promising. Also for what you said about the freedom I was going to have 2 modes one where its free build and one as a grid system so this would be for the grid

1 Like