Adding AI to Space Wars: Ship Battles - A tech discussion about bots


Hello everybody,

as some of you might know, I am currently developing a multiplayer game called Space Wars: Ship Battles. Everything is coming together nicely, but my game has a problem, as most multiplayer indie games do, and that is that there might not always be enough players online to play against, and therefore bot support is vital, to keep players occupied until someone comes online. For both devs, and players who are interested in this stuff, I will here talk about how I'm implementing bot support into my game.

Basics

Most important is that bots are able to find their way across the map, this would be quite challenging (I'd probably implement some A* for you who are interested) if it were not for using the Unity engine, which has a handy feature known as Navmesh. Navmesh allows you to easily implement pathfinding, just bake a map of where the player can go and set the target for your bots, and done.

Shooting

One thing the AI should obviously do, is shooting at players (or other bots), to achieve this, the bots send raycasts (sending out lines basically) to all players in a certain range, and if they find that it is in their line of sight, they will gradually aim towards them, and fire!

Where to move?

Bots will also need logic to determine where they're going. To do this, I am going to give the players the ability to give the bots commands, these commands will be:

  • Follow me
  • Defend the ship
  • Use a turret (to destroy the opponent's ship, very specific to my game, but this could be anything)
  • Attack

Follow the player

This is the simplest, it just pics a  point near the player, and tries to move there.

Defend the ship

The bot will move between random waypoints on the ship, and kill any players it sees.

Use a turret

Also very simple, it will simply move to a turret, enter it and shoot at the enemy ship.

Attack

This will probably be the most difficult to implement, but the bot will probably just move to the enemy ship, and then attack one of two possible objectives, the ship computer to (if the attack is succesfull) activate the self destruct button, or to place bombs at the ship's generator, I might even have it attack the objective it thinks has the highest chance of being succesful, but I don't know yet how I would do that.

What if there are no commands?

If there are no commands, then the AI will try to pick an order based on how many players are where. For example: if there are no players defending the ship, the AI might choose to do that, or if the enemy ship has almost been destroyed by turrets, it will hop into one to deal the finishing blow.


Conclusion

So this is how I will implement bot support in my game, I hope you found this post interesting or helpful.

Get Space Wars - Ship Battles

Download NowName your own price

Leave a comment

Log in with itch.io to leave a comment.