Learn how to program
by playing video games.

RLBot Rocket League Botting Tutorial

Learn Python by playing Rocket League

December 27, 2019
Part of: RLBot Rocket League Botting Tutorial

RLBot is a framework for making Rocket League bots. In this tutorial, I show you how to get started with Rocket League bot programming by building a basic boost stealing bot. This is a great beginner Python project whether you're looking to build a portfolio, or just want to have some fun learning how to write video game AI.

Remember to setup GitHub for this project, especially if you plan on showcasing the RLBots you make in your portfolio.

Links
GitHub repo for this project: https://github.com/learncodebygaming/rlbot_boosthog
Download Python 3 for Windows: https://www.python.org/downloads/
Download Visual Studio Code: https://code.visualstudio.com/download
Buy Rocket League on Steam: https://store.steampowered.com/app/252950/Rocket_League/
Download RLBot: https://www.rlbot.org/
RLBot Wiki for Input and Output Data: https://github.com/RLBot/RLBotPythonExample/wiki/Input-and-Output-Data
RLBot Wiki for Item IDs: https://github.com/RLBot/RLBot/wiki/Item-IDs
RLBot Wiki for Colors and Bot Customization: https://github.com/RLBot/RLBot/wiki/Bot-Customization

To get started with making your own Rocket League bot, you'll first need the prerequisites: the Rocket League game, a Python development environment, and the RLBot framework (links for all these above).

The first time you launch RLBotGUI it will take some time to download the needed Python packages. Once that's done, go ahead and get the example bots by clicking on the plus sign and selecting "Download Bot Pack". Add some bots to each team and start a match to confirm that everything installed successfully.

In the Rocket League game window itself, open the start menu, go to "Options" then the "Video" tab, and in the window settings set the display mode to "Windowed", and set the resolution size to something slightly smaller than your monitor resolution. This will allow you to easily switch between the game window and your code as you're developing.

Clicking "Stop" in the RLBotGUI will stop all the bots from running (and this shut down will be indicated in the console window). Inside the game, the match will continue to run, but all bot activity will be stop. You can bring up the start menu to pause the game. You should leave the Rocket League window open so that when you start a new match it will launch faster (but you can close it at this point if you want).

To start a new bot, click the plus sign again in RLBotGUI and select "Start Your Own Bot!". Give it a name and select Python as the language. I'm calling my bot "BoostHog". This will generate a bunch of files for you, including the configuration and source code for your bot. To find where these files are located, click to the right of your bot in the bot selection list. This will open details about the bot, including where the source files are located on your computer. There's also a handy "Show Files" button that will open the file explorer window for you.

Open the folder with your bot files in your Python IDE and let's take a look around. In the "src" directory you'll find: bot.cfg, which is the base configuration file for your bot; appearance.cfg, which controls what your bot's car looks like; and bot.py, which is the main source code controlling the behavior of your bot.

The ID numbers in appearance.cfg correspond with values that can be found in the RLBot wiki.

Open bot.py and you'll see a class called MyBot that extends from BaseAgent. This is the heart of your bot code in the RLBot framework. Every bot must implement two required functions: initialize_agent(), which runs once when the bot starts up; and get_output(), which is called for every game tick.

The get_output() method receives information about the state of the game in the "packet" parameter. Using this information, it must return a SimpleControllerState that describes what controller inputs you want your bot to provide in order to best react to the current game state. Information about the data structure of GameTickPacket and SimpleControllerState can be found in the "Input and Output Data" section of the RLBot wiki.

Rocket League runs at a tick rate of 60 per second. So every 60 seconds, get_output() will be called and you'll have an opportunity to react by changing your controller state: that is, changing what buttons on the gamepad your bot is pressing, and where the joysticks are positioned.

The default bot behavior when you first generate a new bot is to simply drive towards the ball. You'll find logic in the get_output() method that calculates what direction the car should turn based on the current car position and the current ball position. To do this, you are provided with two helper classes. Vec3 is defined in the util/vec.py file, and it helps you perform math operations between two vectors. Orientation is defined in util/orientation.py and it makes it easier to determine the forward, up, and right directions for your car. Finally, the find_correction() helper function, defined in the bot.py file but outside of the MyBot class, uses the car orientation and the vector from the car to the ball to determine if the bot should turn left or right.

They also provide you with a draw_debug() helper function. This draws a line from your car to the ball, and it also prints inside the game whether the bot is currently turning left or right. These render features are very useful in helping you to determine what your bot is thinking at any given moment.

To create our simple boost stealing bot, this is the plan: 1. We need to figure out where the nearest boost is to our car and 2. We need to tell our bot to drive toward that boost pad location instead of the ball.

This should be enough to get you started with writing your first Rocket League bot. If you think you've got it from here, go for it and let me know how it goes! If you'd like to follow along with me in building this boost hog bot, we'll start writing code in the next video.


Your First Rocket League Bot: BoostHog!
Let's write the code for our basic boost stealing bot! Conceptually it's simple: 1. Figure out where the boosts are located on the pitch and …
Coding a simple Artificial Intelligence for Rocket League
Basic video game AI is built up from many simpler components whose actions are coordinated by decision making logic. Complex behavior emerges as we add …
Ben Johnson My name is Ben and I help people learn how to code by gaming. I believe in the power of project-based learning to foster a deep understanding and joy in the craft of software development. On this site I share programming tutorials, coding-game reviews, and project ideas for you to explore.