Programming a centered bee swarm

Finished version of the centered bee swarm following the player


The bee swarm in “Game of Beelonging” is one of the main parts of the game concept. Whilst playing
the game, there is a bee swarm constantly chasing the player, helping you out when enemies come to
close and assigning a new player on death of the main bee. The swarm is supposed to always be
vertically centered in a compact swarm, even if one of the bees die, which makes programming the
swarm quite difficult.
As I was aware that setting up the bee swarm was the most difficult part of creating “Game of
Beelonging” I started off with it right away.

I began creating ten empty game objects called “slots” representing  all the positions, each of the non
playable bees could go to and added a script to each of the slots containing a pointer to their current
bee, a pointer to the next slot and a boolean that tells if the slot is occupied or if it is not. The idea was
that each bee will constantly check if the next slot is occupied and if it is not, the bee will move to the
next slot. This also changes the pointer to the current bee occupying each slot.
However, there were two problems. First, the last slots pointer to the next slot was always empty,
which means that it would always detect the next slot as unoccupied and every bee in the last slot
would just move away making the next bee follow and triggering a chain reaction that makes every
bee leave the play screen. On the other hand the bee swarm was never centered. Although the bees
move up, when another bee dies, they would always just move one direction making it seem like the
swarm is attached either attached to the top or the bottom of the visible playfield.

To solve the first issue, I created another slot including a bee, that follows the player outside the visible
area. As no enemies appear at this location, this slot will always be occupied and prevent the bee in
the last slot to move up to the next slot, which is the one outside the playfield. I realise, that this is a
rather unconventional solution to a problem like this, but it does not only prevent bees from moving
out of the screen, but also removes null pointer exceptions.
the additional bee following the player outside the visible play area

The second problem was solved by putting all slots into a parent game object called “swarm” this game
object gets the average position of every bee in the swarm on the y-axis and according to the resulting
value adjusts the vertical position of every slot. I.e., if the average y-position of the bees is -1, the
script in the swarm will set the position of the slots to their initial position + 1. This way, the bees will
always vertically stay in the center of the screen.

All in all, I especially learned that it is important to try things out yourself and rely on the principle of
trial and error while solving a problem like this, instead of following tutorials and copying codes without
actually knowing what you are doing. Setting up the bee swarm for the game made me learn to not
only solve problems in creative ways, but also investing time in miscalculation and failure as a way of
understanding a problem at whole.

Comments

  1. Hey dude! Fredrik here.

    Very comprehensive explanation of your design-process, I really like how you started off explaining your first idea of solving it and then explaining the problem of it. That way the reader can follow your way of approaching issues instead of just being provided with the last iteration of your artefact and being told why it’s so great. That way they can be given some pointers of how to think when they are in the same position even though they might be working on something completely different.

    One minor issue that I had as a reader was following exactly what you were saying at some points in the text. Especially the parts where it got a bit techy, it might make perfect sense to you but if you want the reader to also follow along with your reasoning, especially if they don’t have programming experience then you might want to try to read out what you are writing and see if it sounds like it could be understood.

    I liked the summery at the end that you talked about what you learned from working on this artefact. Keep going dude, you’re killing it!

    //Fredrik Henriksen Lövlie (frhe6405)

    ReplyDelete
  2. This post certainly is valuable as the reader can follow your problem and your ways of solving them in a good and easy way. The reader likewise gets a glimpse of how you thought when trying to solve your problems. You start off by explaining what you have been working on in a summary on why you thought it was important to start with it. Your motivation on why you started with the bee swarm was good because the reader gets that it might be the hardest and trickiest part of your game. But further important mechanics cannot be developed without the bee swarm e.g. the replacing of the player bee and helping the player. The reader can follow your creative process when creating the bee swarm from stage one to the finished product. You further explain why you do it in specific ways by doing that the reader gets an idea of what your problem might have been and how you solved them.

    //Adam Olsson (adol2655)

    ReplyDelete

Post a Comment

Popular posts from this blog

The importance of playtesting

More Bees, Less Bugs