Ever since this summer I’ve been struggle to make my AI better. I have Behavior Trees in and really easy to debug logic now, but the path finding has become an issue. The AI stumbled across the age old robotics problem of escaping a concave obstacle. I added a big derelict alien space craft that is integral to the story and a super cool set piece to fight around and explore, but the AI acts like an idiot ramming itself into the structure with the current avoidance AI. The current avoidance works ok for smaller obstacles but when things go on for miles in one direction, path finding seems to be necessary. So, off to AI school I go again.
I looked into the new dynamic navmesh for Unity and its ability to be created on surfaces that don’t necessarily have to be horizontal. I thought I came up with a good hack, but it still doesn’t always work, and the dynamic building of individual navmeshes for lots of ships is going to be a problem when battles scale up. In the video below the agent doesn’t change its angle much, even tho I programmed it to do it and it was doing it a week ago… A great demonstration of how hacky and unreliable it is. It was an exciting idea tho, especially given all the off the shelf stuff you can use with the navmesh like steering and formations. Too bad..
Since I don’t really like how the navmesh system fails a lot and building the navmesh over and over is necessary and slow because you need to keep orienting the plane in different directions so the ship can move in 3D, I decided to start looking into other stuff. 3D A* was an obvious place to go, but A* is not super fast-especially in 3D over great distances. So, I am looking at a Jump Point A* where you can have a mesh of nodes, but you don’t have to traverse symetrical nodes and you can jump to ones where you need to make a decision. I am thinking of it as like a line of site type thing. If you don’t have a direct shot to the target, traverse through nav nodes that connect to create a clear path.
Currently I am working on ways of generating efficient node maps of my levels. I am thinking of using non-uniform cubes represented by a bounds object at runtime. When baking the navmesh info, the cube might start very big like 1km in volume and if it detects a collider within it, it will break into small cubes that test for colliders until you have some areas with finer navmesh data. This way the empty areas of the map would have fewer navnodes to traverse, but when a ship gets in close to an object they need to path find around the nav data will be more refined. This of course sounds great on paper, but I need to make sure I can generate such a thing without locking up Unity or making the player wait an hour for the next scene to load. If it works I think I can add some very cinematic dog fights and ship battles with the small craft dodging and weaving in and out of complex space stations or between capital ships.