Detect if part visible in first person view

I’ve tried many times but failed. What trying to achieve for example: when a part is visible on the players screen it changes the color of it. If you know how to make it please tell me. There was misunderstanding, I mean like this

The lines are the players FOV lines how much he can see
As you see in the first picture the part is not visible for him (a real player)
number5
And if it is visible it will turn green for example (visible for the player)

What You would to achieve this is to use

CurrentCamera:WorldToScreenPoint(part.Position)

it returns 2 things, first one is the X, Y. The second one is whether it is visible on player screen.

u can check out on the devhub

If your game is going to be entirely in first person, then dot products would work just fine. You check out this video about dot products here.

To detect if a Player’s limb or a Standard Part is visible in First Person and if its Player Arms,
Check LocalTransparencyModifier

Imagine u have a part in the workspace and the player (real player) is in first person view and if the part is on his screen it will turn green for example

You can use the method in the first reply but if you wan’t to actually make sure it is visible, (because :WorldToScreenPoint() does not account for other objects blocking said part) you would need another function.

local camera = workspace.CurrentCamera
local target = --the part your trying to detect

local _, visible = camera:WorldToViewportPoint(target.Position)
local blockingParts = camera:GetPartsObscuringTarget({target.Position}, {target})

if visible and #blockingParts == 0 then --if it's within screen bounds AND nothing else is blocking it then proceed
   --change color
end

Doesn’t work

Edited the message, here’s the api reference of it Camera | Roblox Creator Documentation

You could use :GetTouchingParts() with two wedges, or a cone mesh.

:joy: Not like that, the pictures are just a example of the fov

It could still technically work, if you did it like that. I’d suggest using TenBlocke’s solution, though.


only prints “No” and never prints yes is visible
it prints “No” even when the part is visible

You would need to put the 2 lines inside the while loop so they will always be the latest value… Variables stay the same once you define them for the rest of the script unless they’re redefined. And since it’s more of a first person thing i recommend you use a renderstepped event instead of a while loop.

while task.wait(0.8) do
   local _, visible = camera:WorldToViewportPoint(target.Position)
   local blockingParts = camera:GetPartsObscuringTarget({target.Position}, {target})

   if visible and #blockingParts == 0 then --if it's within screen bounds AND nothing else is blocking it then proceed
      --change color
   end
end

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.