How would I make parts of a player invisible if they're behind a wall, similar to among us?

I’m fairly new to roblox scripting, and I cant seem to figure this out. My idea is to use GetPartsObscuringTarget to check if the part’s parent has a humanoid then make their transparency 0 when the default is 1. However I dont know if thats the best way.

1 Like

Take a look at the DevHub API documentation (https://developer.roblox.com/en-us/api-reference/function/Camera/GetPartsObscuringTarget).

In their code example, they have the opposite of what you want, aka the “x-ray” code bit.

local function XRay(castPoints, ignoreList)
	ignoreList = ignoreList or {}
	local parts = workspace.CurrentCamera:GetPartsObscuringTarget(castPoints, ignoreList)
 
	for _, part in pairs(parts) do
		part.LocalTransparencyModifier = 0.75
		for _, child in pairs(part:GetChildren()) do
			if child:IsA("Decal") or child:IsA("Texture") then
				child.LocalTransparencyModifier = 0.75
			end
		end
	end
end

This is the best way to imagine what the method is.

What I’m trying to say is, GetPartsObscuringTarget should work fine, but only if you have your camera in first person or something close.

Doing it for top-down would be no good.

1 Like

What if it were top down? Could i just make two cameras for each player?

No. At that point, using raycasting would be better.
For every render step, you would raycast to all players to check if they are in the character’s line of sight. If they are, they become visible.

2 Likes