Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 5 years ago

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
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 kisty1 111 — 5y

1 answer

Log in to vote
-1
Answered by 5 years ago
Edited 5 years ago

Please provide explanation with your answers. Simply posting code does not spread knowledge of integral scripting processes which helps people understand the logic and reasoning behind your 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)
0
please accept my answer mattchew1010_2 -2 — 5y
0
-1. No explanation was given. User#24403 69 — 5y
0
how do i explain this? mattchew1010_2 -2 — 5y
0
By being smart and not just posting code. DeceptiveCaster 3761 — 5y
Ad

Answer this question