Ad
Still have questions? Join our Discord server and get real time help.
Log in to vote
1

How to detect an object between the player and camera?

Asked by 2 months ago

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

Log in to vote
1
Answered by 2 months ago
Edited 2 months ago

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

Ad

Answer this question