So I’m sure we have all seen those pet eggs in most of the common simulator games. You walk up to them, a billboard UI appears giving information about the egg, you press a key and it opens.
Issue: Although this is probably simple I just don’t know a effective way of doing this, would making a separate billboard UI for every egg and then just find the closest egg when they press a key be effective? It seems there’s something I’m missing that would make this a whole lot easier, perhaps a element of billboard GUIs that I haven’t picked up on (I explored it on the wiki however and haven’t found anything). With my approach it would also have the issue of mobile players being unable to press a button so would I need a bunch of billboard ui’s and every one of them just changes the adornee??
Hey, I was the very first person to make one of these.
Most efficient way (and easiest long-term) to do this is to have a generalized read-only table that contains all the data about pets, eggs, currency, etc. Using a GridLayout, you can generate and sort GUI elements on a BillboardGui based on the data for each egg. Calculate when to draw the BillboardGui by measuring magnitude between player and egg capsule. I did my ‘button’ separately and it changes input depending on the platform the user it playing on. That’s the bulk of it.
My advice is to NOT do anything above because everyone in the world is also doing it. Do something refreshing! Spice it up a bit.
You can have a template BillboardGui and once a player comes within a certain radius from an egg you clone the template, pull the data for that egg from a table like @BuildIntoGames mentioned, and apply that data to the cloned template. That way you only have to make one BillboardGui, and can adjust it based on the egg’s data.
Considering the layout is pretty much the same, you only need to change the text/values.
Loop through all players, check for the closest egg by taking the magnitude between the player and an egg, and compare it to a set max distance. If they’re within the max distance (range) then display the BillboardGui for that egg.
Yes. Iteratively loop through each egg capsule and check the magnitude. Pseudo code example:
while wait() do
for _, eggCapsule in ipairs(eggCapsules:GetChildren()) do
local magnitude = (eggCapsule.Position - player.Position).magnitude
if(magnitude <= 8) then