#Follow World Position with Button

1 messages · Page 1 of 1 (latest)

quasi harbor
#

I want the text button or really any GUI for my api to correctly follow the NPC, I use BillBoardGui for other things like name tags but I want a button or smth but when you parent a button to the bill board which is a child of the model it doesn't work.


function UIComponent:FollowWorldPosition(target, offset, maxDistance)
    offset    = offset    or Vector3.new(0,0,0)
    local maxDist = maxDistance or math.huge

    local conn = RunService.RenderStepped:Connect(function()
        local worldPos = (typeof(target) == "Instance" and target.Position) or target
        local screenPoint, onScreen = workspace.CurrentCamera:WorldToViewportPoint(worldPos + offset)

        local camPos = workspace.CurrentCamera.CFrame.Position
        local dist   = (worldPos - camPos).Magnitude

        if onScreen and dist <= maxDist then
            local viewport = workspace.CurrentCamera.ViewportSize
            self.Instance.Position = UDim2.new(
                screenPoint.X / viewport.X, 0,
                screenPoint.Y / viewport.Y, 0
            )
            self.Instance.Visible = true
        else
            self.Instance.Visible = false
        end
    end)

    self._worldPosConn = conn
    return self
end

#

now that I'm thinking of it tho I might need to parent the button onto a screen gui then the Billboard? idk that sounds excessive but pls help

stuck sky
#

It looks like the buildboard ui isn't centered, did you set the anchor point to 0.5, 0.5?

quasi harbor
#

no I'm not using the buildboard ui, that was my first approach however it took away any interactive things so the button wouldn't click although it was in the proper position