Game
Space Wars: Ship Battles
7 years ago

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


Originally released: Aug 10th 2018
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.



0 comments

Loading...

Next up

This Satuday we invite to watch another #speedpainting of our artist Daniel Faiad.

How great is this scene of #Pecaminosa?

#ScreenShotSaturday | #IndieDev | #DigitalArt

So

i may or may not make an full art of some person or i may just leave this like that-

We are under attack!

Been working lately on lots of 'behind-the-scenes' boring stuff that no one really cares about, so here’s a guy playing the sax for some reason.

#screenshotsaturday

Another house i made long time ago.

Protege el conocimiento, salva la historia. Guardian of Lore es un platformer 2D en el que debes luchar para mantener viva la memoria de la mitología latinoamericana. El juego llegará a Steam el 18 de mayo: https://steam.pm/app/1211740 #ScreenshotSaturday

Showing off player 2 😎

What do you think?

Regular exercise is key for healthy wings.

Try it out!

https://gamejolt.com/games/AeonNightmares/605184

My D&D art for my family so far (WIP if you couldn't tell)