Can someone explain what WorldToViewportPoint() does? This is what I currently have:
1 | while true do |
2 | local CanSeePart = game.workspace.CurrentCamera:WorldToViewportPoint(game.workspace.Part.Position) |
3 | if CanSeePart then |
4 | print ( "Part is visible!" ) |
5 | else |
6 | print ( "Can't see the part!" ) |
7 | end |
8 | wait() |
9 | end |
It keeps printing "Part is visible!", even If I look away. Did I do something wrong?
Thanks.
Takes a 3D world point and returns the following: A Vector3 where the X/Y components map the position in screen coordinates the worldPoint maps to, and the Z component maps how far away from the screen plane the 3d position is (positive if in front of camera, negative if behind). And a boolean which is true if the point is visible on the screen or not.
Source: Roblox Wiki
In other words, you need to use the second returned value of the function to get whether it is visible or not.
1 | local position, isVisible = game.workspace.CurrentCamera:WorldToViewportPoint(game.workspace.Part.Position) |
2 |
3 | print (isVisible) -- Whether the part is currently visible or not. |