How do I limit the rotation of the camera

Hi!, I’m currently making a gliding system, it’s working well so far, I’m basing the character move direction of the camera look vector, but the problem is, I can rotate 180 degrees and the character will follow the same thing, which is not what I wanted, I have been finding ways to solve this problem, limiting the rotation of camera comes to my head, but I have little to no experience in cameras. I just want the steps to make it as I currently have no idea where and what to start with.

Here’s a video of my current gliding system: https://gyazo.com/0fcf25e70ee8c46eedc049192ee442a2

As you can see, I can freely rotate my camera, thus making my character move with it. Is there any ways that I can limit the rotation of the camera ?

1 Like

You could try to see if the camera CFrame has surpassed a limit, and then set it to the limit in the way they are looking. Use Heartbeat for this.

Thanks for your reply! but doesn’t the camera’s CFrame scales with the Character’s CFrame aswell ?

This is an old script I made with my friends.

	RunService.Heartbeat:Connect(function()
		local Cam = Camera.CFrame:ToOrientation()	
		local Val = math.clamp(math.deg(Cam), -30, 30)
		Camera.CFrame = CFrame.new(Camera.CFrame.p) * CFrame.fromOrientation(math.rad(Val), math.rad(170), 0)	
	end)

This script works well. It limits the Camera to only move on a limited angle on the X axis, and limits it from moving on the Y axis. But its not smooth at all, although, I haven’t found anything to make it totally smooth, nor I have found around in the forum. But well, hopefully this helps you.

6 Likes

Hi!, Thanks for replying!, it definitely did help me, I’m going to learn more about your script and hopefully have a grasp of what’s going on, and maybe improvise a version of my own too!

1 Like

What you want to do is separate rotation from movement speed. If you slowly rotate backwards but maintain speed you will make a circle in the sky that looks like what you want.

If you are using body gyro to spin your character then multiply the cframe by .1 or however you like, then apply the speed so that it is always looking at the look vector of the hrp. This way the player will not move to where the camera sees, it will move to where the player sees and the player will be rotating slowly.

If you need help programming this let me know.