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

How would I get an object's on screen position?

I'm trying to figure out how to find a part's 2d position so I can do some comparisons to the mouse's position. I know there are other ways to do this but is there a way to get a 3d object's 2d on screen position?

1 comment

1

You use this function https://developer.roblox.com/api-reference/function/Camera/WorldToScreenPoint on the camera, it returns a vector3 position and a bool indicating if the position provided to the function is on screen. The vector3's z component is the depth from the camera

1 answer

try this:

local camera =  workspace.CurrentCamera
local worldPoint =  part.Position
local vector, onScreen = camera:WorldToScreenPoint(worldPoint)
--onScreen is true or false
--vector is a vector2 point (x,y)

4 comments

0

please accept my answer

0

-1. No explanation was given.

0

how do i explain this?

0

By being smart and not just posting code.

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