Saturday, April 14, 2018

Flocking Steering Behavior

Earlier this year, my new trimester started, and we are tasked to do yet another game. The game my partner and I decided to do was a offline co-op puzzle game. For this trimester, one of the objectives which I needed to meet was a flocking steering behavior. In this blog entry, I will explain to you the things I have learnt for this steering behavior. 

Before I go on and give you a brief explanation on how to implement this steering behavior, I thought I would give you a small insight on the reasons why this steering behavior exists (If you want to know more, the link will be down in the reference list below). The steering behavior is made by Craig Reynolds, in 1986 to simulate a flock of birds and a school of fish, and this was then used in Tim Burton's film, Batman Returns, in 1992. So this shows that not only can this behavior be implemented in games, it can be implemented in film, animations and among other things as well.

On with the explanation then...

In order for me to learn and implement this flocking behavior within the project, I looked at some websites and books about it. One of which I kept coming back to was the tutsplus tutorial page on flocking (reference below). When you want to implement a flocking behavior within your game, you need 3 functions, Alignment, Cohesion and Separation, and the terms used in this behavior are Agents and Neighborhood.

Agents - A fancy word which replaces "game objects". 

Neighborhood - The radius in which an agent enters, will be part of a neighborhood


Alignment()
Alignment() - What this function does is it aligns one agent, with other agents close by, making one neighborhood, that's what this function does. But in terms of technicalities, what it does is it adds the velocity of those agents, and adds them to a computation vector - a total of the vectors, if you will - and it increments how many agents were added within its neighborhood count.



Cohesion()
Cohesion() - What this function does is that it forces all the agents within the flock, to move towards the "center of mass". The way this function accomplishes this is that it adds all the positions of the agents, and this allows the agents to move towards the center of mass.



Separation()
Separation() - This function does exactly what the name says, it separates an agent, away from its neighbors if it gets too close. What this function does is that it takes the positions of the agents, and adds it to the computation vector, and once it gets close enough, the value will be negated, allowing the agent to steer away from the neighborhood. 



References:
Pemmaraju, V. (2013, January 21). 3 Simple Rules of Flocking Behaviors: Alignment, Cohesion, and Separation. Retrieved April 14, 2018, from https://gamedevelopment.tutsplus.com/tutorials/3-simple-rules-of-flocking-behaviors-alignment-cohesion-and-separation--gamedev-3444

Reynolds, C. (Photographer). (2001, September 6). Separation. [digital image]. Retrieved from http://www.red3d.com/cwr/boids/

Reynolds, C. (Photographer). (2001, September 6). Neighborhood. [digital image]. Retrieved from http://www.red3d.com/cwr/boids/

Reynolds, C. (Photographer). (2001, September 6). flocking_around_19 . [digital image]. Retrieved from http://www.red3d.com/cwr/boids/

No comments:

Post a Comment