-
Notifications
You must be signed in to change notification settings - Fork 0
Home
Welcome to the FlowfieldAI wiki!
When I was little, I used to play a browser-based game a lot called "Pixel Legions". It was a strategy game with very simple graphics, where you would play as a certain colour. You'd have to conquer terrain and strategically eliminate all enemy forces on the map.
I was curious about how the AI pathfinding worked for that game, since it looked like every single pixel was able to find its own path. After research, I found it was done by using so-called "flowfields", which is a way to do pathfinding for a large amount of entities. Instead of calculating a path for every single enemy (which can go into the 1000's, if every "pixel" is an enemy), a path to the target would be calculated from every cell, which could be much cheaper depending on how large the level is.
To increase performance even more, the level could be divided into an octree, depending on the location of enemies so that we don't waste resources on empty cells.
Timeframe: January 2023 / May 2023 Team size: 1 Software: Unity Languages: C# Focus: Flowfield functionality Features: - Flocking behaviour - Integration/cost field - Heat map (flowfield visualization)
Here, you can see a flowfield without any calculations applied to it and AI agents placed on random cells.
![](https://private-user-images.githubusercontent.com/58357808/312173045-e788b1c3-1c36-4448-aa34-3fcb3621ab69.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjYxMDgxMDcsIm5iZiI6MTcyNjEwNzgwNywicGF0aCI6Ii81ODM1NzgwOC8zMTIxNzMwNDUtZTc4OGIxYzMtMWMzNi00NDQ4LWFhMzQtM2ZjYjM2MjFhYjY5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MTIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTEyVDAyMjMyN1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTg2YTYzMWIyMzcwYTRjYWRiODMwM2FkMGM4ZDQ3ZjgyMzRlNDUzNWFlNjdlZTAwNjU2ODE0ZTIwYzU1MjI2YzMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.bOTBk4aG6S5gaef4Sc56au_7tPPZhquLeU1GiXHLMF0)
Now you can see the direction of each cell. When an agent collides with a cell, it requests that direction and applies that vector to its own velocity. This means an agent does not need to calculate its own path, but rather just "follows the arrows on the ground".