Anyone know a method to get the screen position (2D) of a point in my ViewportFrame?

I have a ViewportFrame with a player character inside of it, and I am wondering if there are any methods to get the point where the characters head position (vector3) is on the actual players screen (vector2).

are you looking for the players position in the workspace or the viewport?

The players position in the viewport itself

Try using Camera:WorldToViewportPoint on the ViewportFrame’s CurrentCamera.

local HeadPosition3D = Viewport.Character.Head.Position

local PositionWithDepth, OnScreen = Viewport.CurrentCamera:WorldToViewportPoint(HeadPosition3D)

--offset from top-left corner of viewportframe in pixels
--(relative to viewportframe)
local Position2D = Vector2.new(PositionWithDepth.X, PositionWithDepth.Y)
--distance from camera to point in roblox studs
local Depth = PositionWithDepth.Z

--whether the position is visible on screen (does not account for it being behind something)
print(OnScreen)
2 Likes