Hello,
I am making a isometric fallout type game, and I have this camera view that sometimes makes it hard to see the player behind a wall. So, to combat this, I made a script that detects when a player touches a certain part, the wall goes half invisible. I then realized this is hard on my builders, and was wondering if there was an easier way around this? I know someone suggested firing a raycast and making it invisible, but I don’t understand what they mean/how to do it. Here is a video showing the problem. If anyone needs the script I have in the part, here you go:
local part = script.Parent
local wall = game:GetService("Workspace").Roof
local wall2 = workspace.wall
local wall3 = workspace.wall3
local wall4 = workspace.wall2
part.Touched:Connect(function()
wall.Transparency = 0.6
wall2.Transparency = 0.6
wall3.Transparency = 0.6
wall4.Transparency = 0.6
repeat wait(0.1)
local PlayerTouching = false
for i, TouchingPart in pairs(part:GetTouchingParts()) do
if TouchingPart.Parent:FindFirstChild("Humanoid") then
PlayerTouching = true
break
end
end
until PlayerTouching == false
wall2.Transparency = 0
wall.Transparency = 0
wall3.Transparency = 0
wall4.Transparency = 0
end)
Or you can grab all the character models and make a table and then cast ray like Ray.new(cam.CFrame.p,(v.HumanoidRootPart.CFrame.p - cam.CFrame.p).Unit*(v.HumanoidRootPart.CFrame.p - cam.CFrame.p).Magnitude) and get the v from the char table. make sure to have the it as whitelistfilter and have the filter table as the characters in the table
You’re going to have to either use spatial query or raycasting.
Spatial Query Method (not recommended) :
Create a Hitbox around the player’s PrimaryPart, expand it by 50, and detect parts inside that area.
Raycast Method (recommended) :
Raycast from the X, -X, Y, -Y, Z, and -Z axises every 0.15 seconds to detect colliding parts. Do this while filtering the box (put the box in a model/folder) and cast from the PrimaryPart. Once you pick up all your parts, change their transparency.
-- only works for LocalScript's
local fetch = {} --the character table
local plr = game.Players.LocalPlayer;
updateFetch = function()
table.clear(fetch)
for i,v in pairs(game:GetService("Players"):GetPlayers()) do
if v~=plr then
table.insert(fetch,v.Character)
end
end
end
--
task.spawn(function()
while task.wait() do
updateFetch()
table.foreach(fetch,function(i,v)
if v:FindFirstChild("HumanoidRootPart") then
local Ray_ = Ray.new(workspace.CurrentCamera.CFrame.p,(v.HumanoidRootPart.CFrame.p - workspace.CurrentCamera.CFrame.p).Unit * (v.HumanoidRootPart.CFrame.p - workspace.CurrentCamera.CFrame.p).Magnitude)
local Hit,Pos,Normal = workspace:FindPartOnRayWithWhitelist(Ray_,fetch)
if Hit then
warn("Found player!")
end
end
end)
end
end)