-
What do you want to achieve? Keep it simple and clear!
I want to limit a players camera while sitting so they cannot rotate their heads in an unnatural way (looking backwards, looking straight up/down, etc.) -
What is the issue? Include screenshots / videos if possible!
There is no simple way to do this. (either that or I’m just too stupid) -
What solutions have you tried so far? Did you look for solutions on the Developer Hub?
I’ve looked at just about every DevForum post remotely related to my issue. Each one either didn’t work or wasn’t relevant.
First, I tried using the BaseCamera script to limit the rotation. This worked perfectly for the vertical axis (because up is always up regardless of what direction you’re facing), but when adding a limit for the horizontal axis, the camera would act undesirably; when the camera rotation reached the limit, instead of simply being stopped from moving further, the camera violently jerked back within the accepted range.
In hindsight, this wouldn’t work anyway, since the X rotation limit wouldn’t be relative to the player’s orientation (if the player were to look in the opposite direction, their camera would be locked behind them.)
Then, I found this DevForum post that mentioned calculating the angle between the camera and the player’s HumanoidRootPart, and setting a limit from there. This is the closest thing on this forum related to me issue (that I know of.)
Camera Rotation Limit [SOLVED] - Help and Feedback / Scripting Support - Developer Forum | Roblox
The only issue is the solution didn’t go into detail about anything they suggested, which left me and others confused about what to actually do.
This is what I’ve done so far:
local cameraLimit = RS.RenderStepped:Connect(function()
local radians = math.acos(math.clamp(camera.CFrame.LookVector.Unit:Dot(HRP.CFrame.LookVector.Unit), -1, 1))
local degrees = math.deg(radians)
print(degrees)
end)
This returns the angle difference between the CurrentCamera’s LookVector and my HumanoidRootPart’s LookVector. I’ve determined that I never want this angle to exceed 60 degrees in any direction. The only issue is that I have absolutely no clue how to enforce this limit.
I’ll update if I find a solution, otherwise I’ll just bump this until someone else has any ideas.