Make Textlable lock onto part inside a viewport frame

BillboardGui’s don’t render inside a viewportframe, wouldn’t that be nice if so?

A replacement for this could be making a textlable (or frame) lock onto a part inside the viewportframe, but how do you do that? I’m not an expert on math so I’ll need some guidance on how to convert parts position into a 2D vector3 that matches up with the part even in 2D

1 Like

Camera:WorldToScreenPoint()

This is probably gonna make it easier for you than you thought since it returns the position on the screen of a Vector3 in Udim2s and also the depth of the point from the screen. No need for complicated math.

Here’s an example

local originalSize = Udim2.new(1, 0, 1, 0)
local function adjustBillboard()
  local screenOffset, OnScreen =  workspace.CurrentCamera:WorldToViewportPoint(part.Position)
  local BilldboardPos = Udim2.new(0, screenOffset.X, 0, screenOffset.Y)
  local BilldboardSize = originalSize * screenOffset.Z
  billboard.Size = BillboardSize
  billboard.Position = BillboardPos
end

You’d probably want to run this in RenderStepped or something to make it look smooth. Not sure if this example works properly thought, but I guess it gets the point across.

I hope this is what you’re looking for!

It had some bugs but was an easy fix, Thank you so much! your the best : D

1 Like

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