Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do you use GetPartsObscuringTarget?

Recently, I've been trying to make a camera that makes parts blocking the view of the character invisible, I have tried other ways but roblox physics was a pain in the ass. That was until I stumbled upon the :GetPartsObscuringTarget function. I have tried using it however it hasn't been working for me, eventhough I copied other people's example ( it worked for them not for me ) and tried to reverse engineer it to see how it worked because I was confused as hell. Either I don't think I've been using it properly or that it has changed.

If you don't know what the answer to that is, then can you give me another method that would help me achieve what I'm trying to do

1 comment

0

Find a free miners haven uncopylocked and see the code for that xDD Dude, this stuff is pretty tricky

1 answer

✓ Accepted answer

You are able to use Raycasting to detect parts in the way between two points. In this case, the two points would be the character position and the camera position.

local function GetPartsBetweenPoints(Point0,Point1)
	local Direc = Point1 - Point0 --direction of character from camera
	local R = Ray.new(Point0, Direc)
	local PartsObscuring = {}
	repeat
		local Part = workspace:FindPartOnRayWithIgnoreList(R,PartsObscuring)
		table.insert(PartsObscuring,Part) --add obscuring part to table
	until not Part
	return PartsObscuring
end

local Obscuring = GetPartsBetweenPoints(Camera.CFrame.p, Character.HumanoidRootPart.Position)

Using this method, every time a new obscuring part is detected, it will be added to the PartsObscuring table. This table is also used as the IgnoreList for the Ray, meaning that it will not repeatedly detect the same parts. Basically, it will one-by-one detect parts between the character and the camera (on the ray), and add them to the table. You could then used this returned table to set the transparency of the parts in the way.

Hope this helps!

1 comment

0

mattscy, I have tried raycasting and the problem with raycasting was that I couldn't edit the blocks it returned, uhh I'll accept your answer for now and try doing it again and see what went wrong. Thanks!

This discussion is preserved as it was. New answers, comments, and votes are closed.