Hello, i’m a bit rusty, haven’t coded in a while.
I’ve created a “realistic” camera system, it’s in first person and the camera has a limit so it can’t turn over the characters shoulders.
Now the issue is that the mouse.Targer gives a wrong return (it ignores all parts, correctly detects only baseplate or nil). I did a lot of testing and debuging and found out that the problem is with this camera limiter. It seems like the detection is offseted to the side but even then it’s hard to click on an object.
This is the code preventing it from overturning:
local cameraCFrame = char.HumanoidRootPart.CFrame:ToObjectSpace(camera.CFrame)
local x, y, z = cameraCFrame:ToOrientation()
local a = camera.CFrame.Position.X
local b = camera.CFrame.Position.Y
local c = camera.CFrame.Position.Z
local xlimit = math.rad(math.clamp(math.deg(x),-70,40))
local ylimit = math.rad(math.clamp(math.deg(y),-70,70))
local zlimit = math.rad(math.clamp(math.deg(z),-60,60))
camera.CFrame = char.HumanoidRootPart.CFrame:ToWorldSpace(CFrame.new(a,b,c) * CFrame.fromOrientation(xlimit, ylimit, zlimit))
This is not an original code, i’ve found it here on forum and adjusted it a bit. It works perfectly fine.
The camera is set to LockFirstPerson and cameraSubject is set to a certain part in the characters head.
When i disable this code, it works as intended. I’ve been searching the web and the forum for too long and my head hurst at this point.