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

Why does it print even though player cam can't see the part?

The title/question is weird, but the issue I'm having is that when I use :WorldToScreenPoint() I seem to have an issue where the output prints that I can see the part ("SeeL") in workspace even though my camera isn't looking at it. From what I've seen, this returns a vector3 value and a boolean value. Here's the simple code

local Cam = workspace.CurrentCamera
local pos, val = Cam:WorldToScreenPoint(game.Workspace.SeeL.Position)
game:GetService("RunService").RenderStepped:Connect(function()
	if val then
		print("Can see")
	end
end)

Does anyone know what I'm doing wrong?

1 comment

0

Is the part behind any other parts?

1 answer

✓ Accepted answer

First off, this does return a boolean but not in the way you mean. It will always return true according to the Roblox Developer Hub (google is your best friend).

Try using GetPartsObscuringTarget() instead. https://developer.roblox.com/en-us/api-reference/function/Camera/GetPartsObscuringTarget

That seems like it will suit your needs better, and appears to do raycasting so it will actually tell you if its visible. In theory you can just push the CFrame a bit further back, use this function to check for that sEEL brick you want, and if its true then you're good to go.

1 comment

0

Thanks!

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