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

How do i make the walls turn off when reached a corner? Camera manipulation

Asked by 5 years ago

Hello! I was making a camera system for my game and i encountered some obstacles, that i don't know how to solve. Basically i made walls turn transparent using :GetPartsObscuringTarget() and if they are transparent - make them un-transparent. What i want it to do is when i reach or approach a corner - both walls turn transparent. I also tried to use two cast points, but it didn't really help, i made the script even more inefficient, in fact. https://www.youtube.com/watch?v=RAcSK40AtfI&feature=youtu.be

Here's the code i have currently - It's not long, but not very efficient either...

local curCamera = workspace.CurrentCamera
local base = game.Workspace.Base
local player = game.Players.LocalPlayer
local center1 = game.Workspace.Center1
local center2 = game.Workspace.Center2

while wait(0.1) do
    local castPoints = {center1.CFrame.Position,}
    local parts = curCamera:GetPartsObscuringTarget(castPoints, {})
    for i,v in pairs(parts) do
        wait()

        if v.Name == "Wall1" then
            v.Transparency = 1
            game.Workspace.Wall2.Transparency = 0
            game.Workspace.Wall3.Transparency = 0
            game.Workspace.Wall4.Transparency = 0
        end 
        if v.Name == "Wall2" then
            v.Transparency = 1
            game.Workspace.Wall1.Transparency = 0
            game.Workspace.Wall3.Transparency = 0
            game.Workspace.Wall4.Transparency = 0
        end 
        if v.Name == "Wall3" then
            v.Transparency = 1
            game.Workspace.Wall2.Transparency = 0
            game.Workspace.Wall1.Transparency = 0
            game.Workspace.Wall4.Transparency = 0
        end 
        if v.Name == "Wall4" then
            v.Transparency = 1
            game.Workspace.Wall2.Transparency = 0
            game.Workspace.Wall3.Transparency = 0
            game.Workspace.Wall1.Transparency = 0
        end 
    end
end

Answer this question