How would I use Camera:WorldToScreenPoint without it reversing 180 degrees when going offscreen?

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.

1 Like

I just looked at the differences between the two and would prefer to use WorldToScreenPoint

1 Like

There are two methods.

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
2 Likes

Thank you for this! I think I’ll be using the depth method as it seems more flexible.

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