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

How do you use GetPartsObscuringTarget?

Asked by
tantec 305 Moderation Voter
5 years ago
Edited 5 years ago

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

0
Find a free miners haven uncopylocked and see the code for that xDD Dude, this stuff is pretty tricky greatneil80 2647 — 5y

1 answer

Log in to vote
2
Answered by
mattscy 3725 Moderation Voter Community Moderator
5 years ago

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!

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! tantec 305 — 5y
Ad

Answer this question