I am making a tank game and I have marker guis to show friendly and enemy tanks as well as a reticle gui which shows were the tank’s gun is pointed.
I specifically want the reticle gui to be above all tank marker guis, and I want the enemy marker guis to be above ally marker guis.
Basically ,is there a global ZIndex for billboard guis?
There’s a property of BillboardGui, ZIndexBehavior
. Setting BillboardGui.ZIndex
to Enum.ZIndexBehavior.Global
should ignore hierarchy.
Either I’m using it wrong or it didn’t work. I set my reticle frame ZIndex to 3, enemies to 2 and allies to 1, with their respective parent BillboardGui’s ZIndex behaviour to global, but it didn’t work. I than flipped them (allies 3, reticle 1) and it didn’t change anything.
It seems that BillboardGuis would always be primarily sorted based on the distance from the camera. I imagine a solution would be more complex; one thing you could try is changing the property StudsOffsetWorldSpace
, which is the studs offset relative to the adornee. You can change the enemy markers to be nearer to the camera.
local billboardGui = -- wherever you can find it
local cam = workspace.CurrentCamera
local billboardGui.StudsOffsetWorldSpace = (cam.CFrame.Position - billboardGui.Adornee.Position).Unit * 3 -- change this value here to change the distance away from the camera. Right now it's 3. Make the enemy markers closer to the camera
One potential problem for this is that if you’re relying on the BillboardGui to scale with distance instead of setting the offset in pixels, the size of the BillboardGuis may be off. One solution if you are indeed doing this is to change the size to be based on offset and spawn() another thread that constantly changes the size of the BillboardGuis based on the distance from the camera to the Adornee.
Oh, and one more thing: since both the adornee’s position and the camera’s position would always be changing, you’d need to constantly update the StudsOffsetWorldSpace with something like RunService.RenderStepped
.
At this point it’s not worth it, performance would be garbage updating it every frame. Why doesn’t Roblox make this a feature