Easier Way To Detect A Player Behind A Wall?

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)

Any help would be greatly appreciated.

2 Likes

make billboard inside player and make always on top

https://developer.roblox.com/en-us/api-reference/class/BillboardGui

Yes, but that wouldn’t really help all too much as the buildings will have interiors and they wouldn’t be able to see the interior.

Forgot to post the video, here it is

1 Like

oh i get you now you can castray from camera lookvector and when it hit something it do the thing

You can just make a viewport frame and make them highlighted on client

I see, but I don’t know how to do raycasts even after reading the api. It’s really confusing. I also don’t know how to get the camera look vector

1 Like

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

Uhh…What? I really don’t have any idea what you just said, I don’t understand raycasts or anything after reading the documentation.

Is this camera the one related to the client?

What do you mean? I am confused.

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.

Intro to Raycasting (roblox.com)

If you don’t understand Raycasting it’s going to be a lot harder for you even if I spoonfeed you the code directly.

2 Likes

Like camera as in 3D model of a camera or camera in roblox that you use to see around.

Well, the games camera is just the normal roblox camera if thats what you’re asking. I don’t really know what you’re asking.

1 Like

I need to know so i can come up with a example for you, i think you mean the workspace.CurrentCamera only accessible from client.

That sucks, because i’ve been trying to figure out raycasts for some time and it’s really hard. I don’t know what to do even after reading the api.

I still don’t understand what you’re asking me.

-- 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)