Enemy AI

Mark Bohuslav
3 min readDec 23, 2020

--

Today I worked on Enemy AI and implemented their animations. It was a bit of a back and forth day with trying one way then scrapping it and doing it another way, etc, etc. But eventually managed to program in the Enemy AI movement patterns, with designated Idle times and then eventually got the animations going.

Looking in retrospect it wasn’t that hard of a section but somehow in the beginning I struggled with the NavMesh not responding the way I thought it should. I pulled my hair out over and over again not understanding why my current target was not updating. Even after giving in and copying Jonathan’s code to the letter it was still not responding. The culprit was the distance < 1.0f in the IF statement to check if the guard reached a point. For some reason I had to go up to distance <2.9f to get it to work. This took me a while to figure out and the only thing I can think of is that I used a capsule to create the Navigation points for the Guards instead of duplicating the guards and stripping them down.

You see in Jonathan’s older Unity version he was able to duplicate the guards in the scene and then strip out the prefab children, well my build would give a warning when I tried to remove the Child Objects and said I had to open the Prefab directly to make that kind of change. But I know from experience that if I messed with the Prefab that it could and probably would mess up all the instances in the scene of that prefab as well. So hence why I Created a 3D capsule and stripped that down to get the navigation points. So I surmise that maybe the distance from the middle of the capsule is greater then the distance from the guard duplicates on the Navmesh that Jonathan did??? Well that is the only logical explanation that I can think of as to why Jonathan’s formula worked with 1.0f vs my 2.9f which is a pretty long distance when you measure it on in the scene.

I have to say that most if not all of the challenges I have had with the Stealth course actually stemmed from the fact that our current Unity version differs significantly from the version that Jonathan had back in the day. I spent quite a few hours trying to resolve the differences and figure out what to do given the differences. I would highly recommend that they update the Stealth course to account for the changes in Unity, or append some notes somewhere. For example some of the programs and windows are now in completely different places on the menus, The lighting system has changed, the way the Editor handles Prefabs has changed, the Cinemachine Dolly Track changed slightly, even the instructions to where to get the Stealth game assets has changed since now we use FileBase. Even the GIT LFS issues can be avoided for most if proper instructions where included somewhere in the course. While the differences seem minor, they are significant enough to thwart any beginner that does not have much experience and could have saved me about 1/3 of the time I spent so far on this particular coursework.

Anyway, hopefully anyone reading this is forewarned and it saves them some time and frustration. Other than that the rest of the material is great and I truly am enjoying it and learning a lot.

Mahalo,

--

--

Mark Bohuslav
Mark Bohuslav

Written by Mark Bohuslav

Game Developer Intern at GameDevHQ

No responses yet