Create Bot who plays my game

Hello Guys, my game is still in development but I’m already excited how this gonna work out. Maybe you guys have some ideas.
There is no need to explain my game in depth. It’s a 2D RTS type game, where you buy, upgrade and spawn Units with buttons which just head over to the enemy base and fight on there way. The princip is like Clas Royale just in 2D. Later on I want to implement Multiplayer aswell as local playing or campaign vs a bot. How do you implement a bot which plays the game into Unity? I thought about writing different scripts for different difiiculties and just automate in script what a human would do? But this seems so error prone to me. I couldn’t really find something on the web but maybe you can kind of “record” button presses in unity? Or what is the best way to do this for this kind of approach?
Thanks for any reply. Greets!

I would recommend against recording button presses. I’ve spent many an hour trying to make macros to do repetative computer work for me and it always breaks.

The simplest solution, if your game is just about pressing buttons on the screen, is to trigger the methods your buttons trigger from a seperate, AI script, in a set order over a set amount of time.

Your AI would spawn in units at regular intervals and throw them at your players blindly.
A surprising number of single player strategy AIs do this and no one really notices. You’d then playtest each the lists and timings you came up with and test the results to see if it’s fun to play against.

That system would be completely blind though: it wouldn’t respond to what the player was doing. If you wanted something more complex, I would look into AI patterns like Finite State Machines, Behaviour Trees or Goal Orientated Action Planning. Pick one and build that. (Probably Finite State Machines for your game.)

With Unity Learn free for the next few months, it might be worth seeing if they have tutorials for making a Finite State Machine using the Animator window. If they don’t, several youtubers have totally done it.

Any AI will require actions in-game to be seperated from user input though. You don’t want to be giving your AI a camera and telling it to put in inputs like a player. You’ll need to break up all the possible actions in your game into easy to call methods that the AI can use and create some system that lets the AI interpret the world around them. Raycasts and trigger volumes are quite popular ways of doing this but you can also just keep lists of things in a script somewhere. Look into Object Pooling.

Hey Tario, thanks for you’r reply!

These are some keywords I can work with thanks for these informations.

Have a good one!