I want to use Camera:WorldToViewportPoint without it reversing the UI Object’s “Position” when going offscreen
Video of the issue:
I’ve tried looking for answers on the DevForum but I can’t find a topic about this. I’ve also tried Camera:WorldToScreenPoint but that has the same problem.
The first method is using the onScreen bolean to see if the object is on screen, the second method is to use depth and see if it’s negative or less than a certain value.
I find depth to be more adjustable as onScreen boolean only measures a single point so in the case scenario if the dot cursor is really big and halfway offscreen it will turn off since it’s not on screen.
local vector, onScreen = camera:WorldToScreenPoint(worldPoint)
local screenPoint = Vector2.new(vector.X, vector.Y)
local depth = vector.Z
if depth < -0.1 then --allows for some lenience for non point positions
end