Creating A Squirrel


Creating enemy AI can be difficult. When I started working on making the squirrels for the game, I didn't think it would end up being as annoying as it did. Unity doesn't have any sort of navmesh or AI navigation built in for 2D games, so I had to build it from scratch.

At first, I wanted the squirrels to be able to jump and move from platform to platform. In order to do this, I installed a Unity pathfinding library in order to help navigate the environment, however after looking at the code, I realized that adding that would take more time that I had to spend, so I changed it so the squirrels could only move left and right. I then created a navigable grid for the squirrels to use and randomly picked points for them to walk towards. This worked, however the squirrels wouldn't fall when they walked off the ledge. I looked into it, and apparently the library I was using didn't support 2D platformers. Whoops.

So I had to go back to the drawing board. At first I was completely stumped about what to do. I tried modifying the library so that it worked with gravity, but I couldn't figure it out. Then it hit me. Since I changed the design so the squirrel no longer jumped, I didn't need all this complicated navigation code to move it around. I could just could my own AI that walked left or right until it reached its destination. I ended up completely getting rid of everything I'd written and implementing the new simple script.

So, uh, I guess the moral of the story is to try not to overcomplicate things when you don't need to.

Files

FinalBuild.zip Play in browser
Dec 01, 2021

Leave a comment

Log in with itch.io to leave a comment.