Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

preventing custom camera from being able to look through walls?

Asked by
Astralyst 389 Moderation Voter
5 years ago
Edited 5 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.

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?

0
u nvr give full script and im too lazy to redefine everything lol TheluaBanana 946 — 5y
0
nevermind, solved it Astralyst 389 — 5y

1 answer

Log in to vote
0
Answered by
Astralyst 389 Moderation Voter
5 years ago

nevermind, solved it by lerping.

Ad

Answer this question