How bee swarm detects when bee need to collect pollen

Soo bee swarm simulator bees when near pollen they start to collect it, how is this done? i don’t think i mean checking and math, because magnitude check for every pollen field would be costly and bounding boxes would be even more with a lot of parts in the game, another thing is if he used while loop or some event based aproach, anyone have ideas?

Do you mean when you are in the field, or at your base of bee’s?

But in any way, they probally used magnituding or Touched and TouchedEnded to detect if player is zone (please explain a bit better)

When they stand near pollen tile, bees fly to it and collect pollen and then do another things, idk how Onet made detecting this pollen tile soo effective

In that case, try magnituding and use GetPartsInZone on the client and check If a part of the player Is in the zone that is allowed then fire a RemoteEvent and pass over the nearest pollen tile (MAGNITUDING: check for closest polen tile, GETPARTSINZONE: check if in zone)

Swarm modules are used for optimizing things like this, they basically reduce the distance checks to only the nearby units by using a grid and tables

Soo you think that onet used while loop few times a second or soo and then spatial hashing right?

What are you even asking? character limit

I asked about what kind of methood Onet used to make bees detect pollen tiles efficiently

Have you even opened the post I linked?
They use a swarm module, these basically store every position of the pollen in a grid (a tile on this grid may contain multiple bees and pollen), and they also store the position of the bees

With this grid, you can simply get the tiles around the bee, and do distance checks only on the pollen that are in them, that way you only do distance checks on the pollen that’s near the bee and not with all of them

I know, but what isn’t looping through spatial tiles around each bee on the server costly too? especially few times per second?

You don’t loop through them… you directly index them, thus it’s an O(1) and very fast to do every frame

Still i need to loop through given tiles around my bee, let’s say there might be 9 tiles per bee, i need to loop through all the bees, check if there is pollen in those 9 tiles, and if there is perform bee action, wouldn’t this be performant heavy?

ik that you index them but still you need a loop

You’re telling me that you think this is gonna be slow:

for i = 1, 9 do
-- check tile nI
end

?

Not slow, but let’s say we have this:

while true do
  for _, Bee in Bees do
    for i = 1, 9 do
      -- check the tiles around the bee
    end
  end
  task.wait(1/5)
end

Imagine there are 300 bees in the server, it’s almost 9 * 300 * 5 checks per second!

That’s not as slow as performing a check for every honey tile, on every frame, for every bee

Also it depends on the tile size, if the tile size is small, it means tiles contain less items to compare with, thus less comparisons, and if the bee isn’t really near any item, then it won’t do any comparisons at all, because the tile on the grid won’t contain anything

1 Like

Hmmm, i have other idea, would quad trees be more performant maybe? because they are good for static collisions

Sure, quadtrees is a more modern solution

1 Like