How can I limit the X axis of the camera smoothly

Any ideas? I tried to script it from the Base Camera Module but it’s not camera relative and not seems not work correctly (Somehow you can break the limit).

function BaseCamera:CalculateNewLookCFrameFromArg(suppliedLookVector: Vector3?, rotateInput: Vector2): CFrame
	local currLookVector: Vector3 = suppliedLookVector or self:GetCameraLookVector()
	
	local currPitchAngle = math.asin(currLookVector.X)
	
	local xTheta = math.clamp(rotateInput.X, -MAX_X + currPitchAngle, -MIN_X + currPitchAngle)
	
	local constrainedRotateInput = Vector2.new(xTheta, rotateInput.Y)
	
	local startCFrame = CFrame.new(ZERO_VECTOR3, currLookVector)
	local newLookCFrame = CFrame.Angles(0, -constrainedRotateInput.X, 0) * startCFrame * CFrame.Angles(-constrainedRotateInput.Y,0,0)
	return newLookCFrame
end
1 Like

I posted a minimal CameraScript here.

1 Like

I don’t know what that has to do with what I’m asking.

1 Like

The code I posted there shows how the camera pitch (aka X axis rotation) can be calculated and constrained. Take a look at the pitchCameraBy function.

The problem with that script is that overlaps the current camera and it’s a huge problem for me because I’m making an FPS that uses the standard Roblox camera and I just want to limit the angle of the X Axis when the player uses the bipod (Like Battlefields do).

1 Like

AFAIK the only good way is to temporarily disable the built-in CameraScript while turret controls take over

So I’m using your script (Very useful :slight_smile:) and I’m struggling with setting a max angle of the X Axis and make the camera relative to the player (Like CameraSubject does when the camera is set to Custom) but I didn’t find any useful post explaining how to do it.

Here is the Baseplate with your script and some things I add (Press B to change the camera) just to test it.

Camera.rbxl (46.6 KB)

1 Like

Hi, I took a look at the place file but I’m not entirely sure what you want to happen instead of how it currently works?

In the place file, when switching the camera you can rotate on the X axis all the way around. It looks like OP wants to restrict the camera movement on the X axis while keeping that restriction relative to the player (for example, only being able to look in front of you while in first person). The camera is currently not working in this way.