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

Detecting walls between character and camera to zoom in, problem?

Asked by
KoreanBBQ 301 Moderation Voter
8 years ago

Hi I'm making my own camera and I'm using Raycasting to detect walls between the camera and the character.

However, although it does not error, when your camera is blocked by a wall it glitches and goes up and down up and down, very annoying.

if you can relate, its a little similar to making a 3D mouse cursor and not making it "ignore" itself..

heres's the code, how can I prevent that from happening.

local createRayAndFindColliding=function(origin,dest,length)
        local ray=Ray.new(origin,(dest-origin).unit * length)
        local ignore={ray}
        local collidePart, collideCoord=workspace:FindPartOnRayWithIgnoreList(ray,plr.Character:GetChildren());
        return ray,collidePart,collideCoord;
end     


game:GetService("RunService").RenderStepped:connect(function()
    if changing==false then
        local ray,collidePart,collideCoord=createRayAndFindColliding(plr.Character.Head.Position,cam.CoordinateFrame.p,50)
        print(collideCoord)
        print(collidePart)
        if not collidePart then
            cam.CoordinateFrame=CFrame.new(plr.Character.Torso.CFrame.p+currentCamView,plr.Character.Torso.Position)
        elseif collidePart and collidePart:IsA("BasePart") and collidePart.Name~="Terrain"  then
            cam.CoordinateFrame=CFrame.new(collideCoord,plr.Character.Torso.Position)
        else
            cam.CoordinateFrame=CFrame.new(plr.Character.Torso.CFrame.p+currentCamView,plr.Character.Torso.Position)
        end
    end
end)

Answer this question