Hello there. I made my own camera script for a game I am making.
Long story short, I don’t know how to clamp the rotation axis so that it face upside down.
Here is a clip of how it currently looks like.
Let me load another one…
I have tried one method. Storing the mouse delta in a variable then simply stopping adding movement if that variable gets over 89 and -89. However that doesn’t work when the orientation of the character is different.
In other words I need to clamp the cameras rotation relative to the players body.
One other thing. I did try setting it using the ToWorldSpace method and instead using it like that however it seemed that the camera would rotate around the player if it rotated. I do not want this.
Any help is appreciated.
Here is the script I currently have as of now.
-- This is run every frame
local function UpdateCamera(DeltaTime)
local MouseDelta = UserInputService:GetMouseDelta() * GameSettings.MouseSensitivity
CameraRotation = CameraRotation + MouseDelta -- this was the variable I used previously to do the clamping.
CameraRotationMatrix *= CFrame.new(0,0,0,rad(MouseDelta.Y),rad(MouseDelta.X),0,qW)
SubjectPosition = SubjectPosition:Lerp(
Character.PrimaryPart.Position,
DeltaTime * 5
)
Camera.CFrame = CFrame.lookAt(
Camera.CFrame.Position:Lerp(
Character.PrimaryPart.Position+(CameraRotationMatrix.LookVector * -CameraDistance),
DeltaTime * 2
),
SubjectPosition,
Camera.CFrame.UpVector:Lerp(
CameraRotationMatrix.UpVector,
DeltaTime * 3
)
)
end
The rotations of the camera are fine. I like them like that. However, I would like to know if there is a way I can clamp the movement of this camera relative to the Character.
I can’t seem to clamp my camera on the X or the Y Axis.
I've tried ToWorldSpace, XVector.X, Difference Between Head.CFrame and CurrentCamera.CFrame (closest I've gotten to get correct difference between camera and head, still read only)