preventing custom camera from being able to look through walls?
Asked by
6 years ago Edited 6 years ago
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.
01 | local Raycast = Ray.new(Head.Position, (Camera.CoordinateFrame.p - Head.Position).unit * Offset.Value) |
02 | local Part, Pos = workspace:FindPartOnRayWithIgnoreList(Raycast, Character, false , true ) |
04 | Camera.CoordinateFrame = CFrame.new(Head.Position) |
05 | * CFrame.Angles( 0 ,math.rad(AngleY), 0 ) |
06 | * CFrame.Angles(math.rad(AngleX), 0 , 0 ) |
07 | * CFrame.new( 1 ,. 5 ,Offset.Value) |
09 | Camera.CoordinateFrame = CFrame.new(Head.Position,Pos) |
10 | * CFrame.Angles( 0 ,math.rad(AngleY), 0 ) |
11 | * CFrame.Angles(math.rad(AngleX), 0 , 0 ) |
12 | * CFrame.new( 1 ,. 5 ,Offset.Value) |
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?