Game
Space Wars: Ship Battles
6 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

So

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

Smile! Here, take some happy pills! ✨💊 #Blender #3DModelling #3DArt Buy me a Ko-fi: https://ko-fi.com/barbarafb_

Finished a project I've been working on over the last few days!

Modeled and textured in Blender.

#3dart #lowpoly #npbr #fantasy #hut

Today I was setting up the location of the first boss. His name is "Father" and he is the first of the Patagonians. His task is to guard the road to the House.🛡🗡 Bookmark pre-launch page🔖🔖🔖

https://www.kickstarter.com/projects/rdvindiegame/the-patagonian…

I have added rewards for quests so that villagers can give you something in return for your hard work helping them. 🥳

I want to know - what's your favourite quest reward?

Sometimes the suction cup get sticky. Small animation I made in Blender after doing my tutorial on picking up/dropping objects in animations. Crate model by jQueary (https://sketchfab.com/3d-models/game-ready-sci-fi-crate-d98deca6…).

Demonstration of the spells and their effects :)!

a drawing I did because I was bored😪. But I love how it turned out.😊

Who's is this little cutey👸 here? Thanks🙏 for a gorgeous fanart @WheNa! Feel free to share your arts, screenshots, or videos with #playzelter or #zelter hashtags! #pixelart #animating #unity3d #animated #indiegames #unrealengine #animate #conceptart

Auto-chess meets Clash Royale in an intense strategic battle. Outsmart your opponent, hide your play and crush their armies! Empire Builder just got another major update, check it out! https://gamejolt.com/games/EmpireBuilder/558901