What are you attempting to achieve? (Keep it simple and clear)
Making (not sure what it is) textlabels or guis that kind of stick to a surface. What is the issue? (Keep it simple and clear - Include screenshots/videos/GIFs if possible)
Here are some examples:
(Neighborhood war) https://gyazo.com/26274824e28f882a1ed8396d9c57134b
BillboardGuis allow 2D GUI objects to exist in 3D space. The contents always face the camera, and are positioned based on their parent or, if it is assigned, their BillboardGui.Adornee.
I got this for my own game as well, i’d be happy to help.
local function WorldToScreen(Position, Mouse, Camera)
local RealPosition = Camera.CoordinateFrame:pointToObjectSpace(Position)
local Angle = math.atan2(RealPosition.x, -RealPosition.y)
local ViewSize = Vector2.new(Mouse.ViewSizeX, Mouse.ViewSizeY) / 2
if RealPosition.Z < 0 then
local ATY = math.tan(Camera.FieldOfView * math.pi / 360)
local AT1 = Vector2.new(ATY * ViewSize.X / ViewSize.Y, ATY)
local UPOS = Vector2.new(-RealPosition.x, RealPosition.y) / RealPosition.z
local SPOS = ViewSize + ViewSize * UPOS / AT1
if SPOS.x >= 0 and SPOS.x <= Mouse.ViewSizeX and SPOS.Y >= 0 and SPOS.Y <= Mouse.ViewSizeY then
return SPOS, Angle
end
end
return nil
end
This function will return a screen position based on a world position.
local pos = WorldToScreen(mouseTarget.Position,utilities.Mouse,game.Workspace.CurrentCamera)
--some label
label.Position = UDim2.new(0,pos.X,0,pos.Y)
local UIS = game:GetService("UserInputService");
local key = Enum.KeyCode.E;
local gui = script.BillboardGui;
local plr = game.Players.LocalPlayer;
local char = plr.Character or plr.CharacterAdded:Wait();
local Selected;
local Distance = 6;
local Places = {
game.Workspace.Place,
}
UIS.InputBegan:Connect(function(k,i)
end)
game:GetService("RunService").Stepped:Connect(function()
gui.Parent = script;
for i,v in next,Places do
if ((v.Pos.CFrame.p - char:FindFirstChild("HumanoidRootPart").CFrame.p).Magnitude <= Distance) then
gui.Parent = v;
Selected = v;
end
end
end
Hey, thanks for the answer. I’m not so good at all does math.atan, math.tan function etc.
So I guess i’ll just pass and not add it into my game.
TL;DR
More advanced than I thougt.
I guess i’ll just use @Dandystan answer, might not be the perfect way, but i’ll just use magnitude to see if someone is too far away etc. But kinda sucks that I cant use an image but… nevermind
You could, alternatively, use BillboardGui.MaxDistance, which determines the maximum distance (away from the camera) in which the contents of the container will be visible.