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

How to detect an object between the player and camera?

I have a game where the camera is at a permanent angle, for example like Mario but at an corner angle.

At times parts would go in between the player and camera, is there a way to detect this and them make said part transparent? I would try using rays being made using render step but is there a better practice of this.

1 answer

✓ Accepted answer

yes, use :GetPartsObscuringTarget() which returns parts that are blocking specific vector3 positions in a array, which would be the player's character Torso or HumanoidRootPart.

basic example

--client

local player = game.Players.LocalPlayer
local char = player.Character or player.CharacterAdded:Wait()
local camera = workspace.CurrentCamera
local objects = camera:GetPartsObscuringTarget({char.HumanoidRootPart.CFrame.Position}, {}) -- 2nd parameter is a ignorelist to ignore parts.

for _,part in pairs(objects) do
	part.Transparency = 1
end

:GetPartsObscuringTarget()

1 comment

0

i assume this to go in to a local script but where does the local script go in to?

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