March, 4th 2018
Creating 2D Enemy Movement in Unity that is Able to Avoid Obstacles
How can I make an AI that avoids obstacles WITHOUT using NavMesh?
This link contains oStaiko’s answer to the above question, and describes two standard ways to deal with basic enemy AI movement, especially on a 2D plane. These two ways are: a waypoint setup and a more “vision” focused setup.
Waypoint Setup Pros/Cons
- Good on static maps where enemy can “know” the entire map
- Deciding fastest routes can be tricky
Vision Setup Pros/Cons
- Works better for non-static maps/obstacles
- More difficult to setup (scripting-wise)
- Better for open maps, can work poorly in more constricted spaces
Example Script for Setting Up Raycast AI to Move Around Obstacles
Unity 3D – Enemy Obstacle Awareness – AI – Code Sample
This link leads to some sample C# code for setting up a script that gives an object raycast vision to avoid obstacles and refocus on a target.