I want to be able to tell if a certain object is in the view of a player's screen. Obviously I could use Mouse.Target, but that would only work if the player looks directly at the object. I have absolutely no background knowledge on how to do this. I'm not sure if this is complicated as writing 4 different math equations, or if it's as easy as typing 3 lines, but it would help if someone pointed me in the right direction.
✓ ANSWER ACCEPTED
QUICK QUESTION: How do you tell when something is inside of a player's view?
1 answer
✓ Accepted answer
You can use Camera:WorldToScreenPoint() to see if a point is in front of your camera. Given that, we can then use Camera:GetPartsObscuringTarget() to see if any objects obscure the point.
local screenPos, inFront = camera:WorldToScreenPoint(part.Position)
-- Check screen bounds
if inFront and screenPos.X >= 0 and screenPos.Y >= 0 and screen.Pos.X <= mouse.ViewSizeX and screen.Pos.Y <= mouse.ViewSizeX then
local obstacles = camera:GetPartsObscuringTarget({part.Position}, {})
if obstacles == {} then
print("Success!")
else
print("Object blocked")
end
end
3 comments
1
thebayou!! I SEE YOU PLAYING POLYGUNS WITH ME XD
0
nice but you didn't have to comment to make me check your answer
0
lol sry just didn't want to be ninja'd by a comment
This discussion is preserved as it was. New answers, comments, and votes are closed.

4 comments
Something in the Camera could help, like a method
Oh, here we go, I found something.
"WorldToScreenPoint: Takes a 3D world point and returns information regarding its 2D screen location, its depth, and whether it is visible on the screen or not.". Thanks for the suggestion.
check out my answer below v