The extent of any AI I’ve ever written is mashing together macro’s in excel to streamline complicated tasks.
So when it came to developing an AI for Metric, I decided the best foot forward was too keep it simple and build on that.
Follow the Bread Crumbs
I set it up that each track will need a set of ‘nodes’, the green tennis balls in the image below. The node’s are no different than any other track/sandbox item, and can be added, edited and deleted in the same fashion as the rest of the track parts.
Once the track nodes were initialized, it was as simple passing the list of nodes as a ‘List’ collection and have each ship individually chase after the nearest node. Once it reached a certain threshold of minimum distance, it would increment up the list to the next ‘Node’. You can see the first iteration of the code below.
As it turned out, this worked incredibly well on almost the first try. You can see it in action the video below:
I had to fiddle with the cut off of dot products and everything, and there is definitely some room for improvement, like factoring the amount of thrust more heavily on how ‘on course’ the ship is, but all and all, it’s a very effective first try at bot AI.