I've been making a custom camera, and I need the camera to not be able to look through walls,
(the best way to explain "looking through walls" is, try have shiftlock on and stand against a wall on your right side, the camera will clip through it)
This is the closest that I've got.
local Raycast = Ray.new(Head.Position, (Camera.CoordinateFrame.p - Head.Position).unit * Offset.Value) local Part, Pos = workspace:FindPartOnRayWithIgnoreList(Raycast, Character, false, true) if not Part then Camera.CoordinateFrame = CFrame.new(Head.Position) * CFrame.Angles(0,math.rad(AngleY),0) * CFrame.Angles(math.rad(AngleX),0,0) * CFrame.new(1,.5,Offset.Value) else Camera.CoordinateFrame = CFrame.new(Head.Position,Pos) * CFrame.Angles(0,math.rad(AngleY),0) * CFrame.Angles(math.rad(AngleX),0,0) * CFrame.new(1,.5,Offset.Value) end
It pretty much works; however, the camera would just spas like crazy when I try to look through a wall, how would I fix/or is there a better way of doing stuff?