Optimizations for BillboardGUI animations?

Hello fellow developers!

I am working on CollectionService based system for all BillboardGUIs with associated tag to have animation for pop-up when in proximity. The real issue is, I want to find a optimized solution that would both efficiently detect player’s position and trigger event and at same time not have too much overhead. Would RenderStepped & Magnitude (for position checking) work fine for this case? This may sound like bit obvious and strange question but I am trying to get better at scripting and want to know about what would be the best solution.

Just tweak the MaxDistance property of the BillboardGui to your preference and it will stop rendering the BillboardGui when the player is not near it and then render it again when they are.

Hi,

I am aware of this.. that’s not what I was asking. Since ROBLOX doesn’t have native feature for adding scripted behavior for MaxDistance, you would have to make a custom script for adding Tweening (ex. pop-up) when going close enough or away if you wanted to have that behavior in game. This is what I wanted to implement, my current billboard guis just pop up out of nowhere without tweening because it uses MaxDistance.

local visible = false
task.spawn(function()
	while true do
		local dis = game.Players.LocalPlayer:DistanceFromCharacter(workspace.Part.Position)

		if dis and dis < 5 and not visible then
			visible = true
			--TweenIn()
		elseif dis and dis >= 5 and visible then
			visible = false
			--TweenOut()
		end

		task.wait(0.1)
	end
end)

They added a new thing for detecting things in a radius of something. Maybe this would suite your usecase? However I’m not too sure how this works performance-wise.

Unless you have thousands of billboards, looping through every billboard and using a magnitude check would probably have a minimal cost. If you do, though, you could use an octree system or divide the billboards into cells based on their position.

I guess that would be true. Will be looking in those in case it ever get out of control & Collections that @WhoAmIMaybeMe mentioned.

Thanks to everybody for guiding me on correct path!