Role: Programmer
Engine: Unreal
Duration: 4 weeks
Year: 2021
Team Size: 5 (2 Coders)
Sheep Herdle is 3D platformer with some puzzle elements targeted at kids. The player controls a dog with the goal of collecting all the sheep spread about the level.
​
For this project I almost exclusively worked on the flocking and pathing behavior for the sheep. I have always found flocking behaviors interesting and satisfying to do. This is by far my deepest dive into pathfinding beyond AStar and provided me with a lot of useful experience.
​
The two systems I made in this project layer on top of another to create what I find to be some pretty fun results.
Pathing
For the pathing I wanted something that would scale well with more sheep and would path from the player in a semi smart way, like not getting stuck in dead ends. This led me to flow fields which I had touched a bit on before during jams.
​
​

Hex Grid

The grid drawn within a distance from the player
At the base of the whole system is a hex grid. I went with this as the paths on a square grid became too "square", even with diagonals.
​
The hex grid handles mapping out the world using sphere traces and assigning connections between hexes.
It also does conversions between world and grid.
​
The hexes themselves hold date necessary for the flow field as well as pointers to neighbors and world position.
Flow Field
The flow field uses a breadth first search to find the shortest path to one point, the dog. Using the assigned weights I can then give each hex a direction for the path.
​
Since I want the sheep to flee and not run to the dog I have some extra steps. Multiplying all the values from the previous search with a negative value lower than -1 I can reverse the direction of the flow while also making tiles with a longer path to the dog more attractive.
This then gives the sheep a rudimentary foresight, allowing them to avoid or get out of dead ends.
​
The final product of the flow field is that anywhere around the dog a sheep can use it's current position and get a direction to go.

The arrows point in the direction the flow field would send the sheep
Flocking
For the flocking I did a boid simulation as I like the simplicity and the results. I had also worked with it a bit before so the familiarity helped.
​
Boids work on three simple rules, cohesion, separation and alignment. Cohesion involves bunching up, separation is keeping a distance, and alignment is about moving in the same direction.
These all add together to a desired direction for the boid to move towards.

Boid Manager
The boid manager is where most of the logic is. It is written in a singleton pattern and holds every active boid.
A boid can query the manager it will go through all nearby boids using the three rules before spitting out a new direction for the boid to move in.
Boid Agent
The boid agent holds tweakable values like the range and weight of the different rules.
It also adds itself to the boid manager and runs its own tick for updating the direction.