Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

preventing custom camera from being able to look through walls?

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?

2 comments

0

u nvr give full script and im too lazy to redefine everything lol

0

nevermind, solved it

1 answer

This discussion is preserved as it was. New answers, comments, and votes are closed.