Hi everyone! I’m planning to include a commonly used system in my game where where you can press ‘E’ to interact with a nearby item/npc/whatever. I was planning on making this apparent by including a Billboard GUI with a short render distance. On top of that, I wanted to make the billboard GUI fade in and out or play some animation rather than just popping in. This can be done by constantly checking the magnitude of the players position and the GUIs position fairly easily, but here’s where I’m wondering if there is a better way. I am planning on having many interactable objects in the game and it feels costly/redundant to be constantly looping through all of the interactable objects for magnitude when there are so many. Here’s some other options I’ve considered:
Region3 (loop in a shorter range of interactable items)
Explosions (probably not a great solution but it would definitely work)
So what I’m wondering is if there is a way to detect when the billboard GUI is rendered. I would use it by having the billboard GUI at a short max distance as well and invisible. So when that distance is crossed, I’m looking for an event of sorts that would let me know that I should enable the show GUI animation. After that I would be constantly checking the magnitude to play the affect backwards once the range is crossed (I would have to increase the max distance temporarily so it won’t dissapear before that happens). This would be great because I wouldn’t have to be constantly looping through all the interactable items on the players client! Is there any way currently to pull this off?
You should handle the GUI appearance client-sided, which shouldn’t be too bad.
When you input some key and try to “click” on the gui, you could send to the server which GUI you are clicking (or whatever part it’s adorned to) and do a distance check there for some anti exploits.
1 Like
Right, this is more a matter of efficiency since I don’t want to be checking magnitude on potentially hundreds of interactable items. Either way it would all be on the client and I would send the closest over to the server to validate distance or something along those lines. In this case I will be uses a keybind such as ‘E’ instead of clicking so I will need to be checking everything. The problem here isn’t about the activation it’s about efficiently adding a smooth pop in effect for the billboard GUI rather than the default with max draw distance.
In reality it really isn’t all that expensive, I just wanted it to be immediate rather than doing a while loop since the player can move fairly quickly in my game and therefore can close the distance between the max distance and the object in less time than the time it takes to loop (which I could also lower but that means even more processing).
1 Like
Pretty sure this is what you meant by Region3, but if not, you can split the load into zones.
You would only check the zones you’re in and ones around it. The size of the zones would have to be radius x radius
.
Would look something like this:
Red isn’t loading any guis
Yellow can either load all, any or none (depending on your location)
Green is loading every gui
Yeah that definitely seems more efficient than looping through all of them, at least in my case (although I’m not exactly sure how much a region3 costs in terms of performance). Unfortunately it still doesn’t solve the the delay you get from looping these searches since you have to make a new region3 every time which shouldn’t really be done on a RenderStep (which would be essentially instant).
I wouldn’t create a new region on every step if I was you, I’d create them on start and keep them in a table. Just for efficiency and easier management, I’d cut apart the grid in rows and store rows as tables in the main table. Inside the rows, the table would be all regions inside that row by order.
And then you can easily find the region3 you’re in by flooring your position on x axis (or whatever you choose) to get row table and then same thing on y axis to get the region.
Index-1 would be the left region, Index+1 would be the right region.
Rows up and down on same 3 indexes would be bottom and top regions.
Hopefully, you understand what I meant…
1 Like
That’s a really interesting way of doing region3 I’ve never tried breaking it up into grids like that! I’ll have to give that a shot because that could significantly improve the performance and it would be relatively easy to find which region the player is in.
Makes me wonder if it’s worth trying to add individual region3s to each object and then just using an event to see if they have entered it. For stationary objects anyway.
Just found a pretty decent solution so I thought I’d share in case anyone comes across this thread. I essentially made invisible parts on each of the activation points and put a Touched event on them to simulate it in real time. Then I added a simple while loop for magnitude to make it disappear. It all runs on the client so it seems fairly reliable. Thanks for the help everyone!
https://gyazo.com/0eac19eea2a601641e503f2d5e00db2e
7 Likes
check the distance between the camera and the billboard gui adornee