My original Idea was to create a random 2D map generator but after looking further into steering it seemed more fun to explore and implement these techniques. I went through some of Daniel Shiffman’s videos about steering behaviours to help me with my implementation. For my demonstration I wanted to experiment with some steering AI techniques to create a small 2D game where the player has to chase fleeing agents while being pursued. There were a lot of different types of techniques but I could only implement some of them. My demonstration will be using the following steering techniques in 2D:
Seek - will have an agent that calculates the desired velocity from the agent to the target by subtracting the target’s position from the character’s position. This results in a force vector which is the shortest path between the character and the target. The agent will then continuously move towards the target by following that vector.
Arrive - similar to seek but once it reaches within a certain radius to the target the agent will slow down and come to a stop.
Flee - this technique will calculate the velocity between the agent and the fleeing agent which is similar to the Seek technique which calculates the force vector between the agent and target but instead of moving towards the ‘target’ it will move in the reverse direction away from the agent.
Follow-path - this technique has a path drawn on the screen where the agent calculates the next destination point on the path from it’s current location. When it reaches the desired point on the path it will then calculate the velocity to the next point. In my demo once the agent reaches the end of the path a new path will be randomly generated. Daniel Shiffman’s example used the dot product to calculate the steering once the future position was off track. I tried to implement this but took too much time and went for a more simple way.
Pursue - For this technique the agent would try to predict the path of a target and chase them. I used this in my demo by making the Agent pursue the player but because the players movement was not code to move using vectors the agent would predict the future position by using ‘fake’ vectors produce by the player when pressing the movement keys.
Some other techniques in steering not used in this demo are: Obstacle avoidance Flow field Flocking Wander - I tried to implement this but had a lot of trouble and the movement did not look correct so I just scrapped it.
Different techniques used in steering can be used in many aspects of game development. Some examples would be using follow-path in a car game to keep the cars on the racing track and making their motion look more realistic. Another example where steering can be used is in stealth games using techniques such as wandering and seeking to make agents wonder around the map and only seek if the player is in their line of sight at a certain radius.
What the demo does: The demo will consist of two scenes, the first scene which will demonstrate each steering technique that were listed in the used techniques. It will show my attempts to implement some of the steering techniques and what the movement of the agent looks like. The second scene will combine the techniques to create a small points system game. As a player you will have to chase down the agents while they flee from you to gain points. The more you tag the more points you will gain. After tagging an agent they will be stationary for a few seconds before they become a pursuer to make it harder for you to gain points.
How to use it: To use the first scene you will just have to activate and deactivate the scripts you want to test and deactivate the ones you don’t. You will be able to move the target location around through the use of the left click mouse button for the scripts seek, arrive and flee. For the follow path script you will be able to generate a random path instead of generating a new target location using the left mouse button. To use the final scene you will just have to control your avatar through keyboard input UP,DOWN,LEFT,RIGHT arrow keys or W/A/S/D buttons for movement and just move around the space trying to score higher points by colliding with the agents.
Video documentation:
Used as Reference: Daniel Shiffman repository: https://github.com/shiffman/The-Nature-of-Code-Examples/tree/master/chp06_agents Unity Asset 2D Steering: https://www.assetstore.unity3d.com/en/#!/content/21381