Update 1: Got pathfinding working, yay! I had a bit of a tussle with navmesh (there seems to be no documentation on it) but that was the only annoying part. The navmesh was building fine in the editor, but it would completely fail on play, giving either no navmesh at all, or one random chunk in one corner. Apparently the Agent Radius setting in project settings or the RecastNavMesh object in your level is just a holdover that should have been removed. Messing with it just breaks things. You have to set up an “Agent” in the navigation system page of project settings. Once that info was found online, it was pretty smooth sailing.
My enemies are super simple. The first iteration of the stupid ones in the build had only three functions. 1. They always rotate to face the player. 2. They cast five short traces outward and apply a force away from anything they contact, and 3. They have a constant force applied toward the player. It’s incredible how far such a simple system will get you. Unless you get directly on the other side of a wall from them they follow you around to a certain distance, and seem to intelligently dodge around obstacles and shoot you. And even if you fly through a door or around a corner, they often have enough momentum and general wobble to follow you. If you were on the other side of a closed door from them, they will bob close enough to trigger the door, wait for a sec for it to open, and then go through after you. Ah, for firing they have a sphere collision in front of them on the end of a spring arm. That determines what they “see”. If the player overlaps that, they fire. The enemies in the build actually have a few extra features. I added a little bit of “spring” force with exponential falloff to their object avoiding forces to help them not run into things as much. Also, if their front-side traces register hits, but their forward trace does not, they apply extra forward force. This lets them push through narrow spaces quite nicely.
To make them follow a path I simply had them constantly push toward the next path point, rather than the player. If they player leaves their targeting volume for more than a second or so, their AI controller finds them a path to the player (with Find Path to Location Synchronously). That gives an array of path point locations, the first of which is passed to the pawn to rotate and move toward. There is a threshold radius to register when the pawn has reached it’s target point, upon which it switches to the next point location. If at any time it “sees” the player with its targeting volume, it stops following the path and resumes its “dumb” player-following. I threw in a little random side-to-side dodging so even if it gets stuck directly behind a turret (which currently don’t affect the navmesh) it will manage to bob around it and keep going after a second or two. Before figuring out the navmesh settings they would sometimes get stuck on 180-degree corners, since the best path made a little cluster of points close enough together that the AI could register reaching multiple points from one side of the wall. I just increased the agent radius for the navmesh a bunch so they stay out from the walls more. Not a 100% perfect solution, but it will work fine unless I want really tiny tunnels.
Sorry for the wall of text. I thought this thread could be vaguely interesting to some if I explained what I was doing and how, rather than just posting a list of updates. Here’s a bit of rough concept art to finish off:
*P.S. . . . Now I just have to make the AI smarter so it can be more stupid again and not track you down to the ends of the earth and kill you . . . *