RLBot

1.68.0 · active · verified Thu Apr 16

RLBot is a Python framework for developing custom AI bots to play Rocket League in offline matches. It provides access to real-time game data, such as car and ball positions, and allows bots to send controller inputs back to the game. The framework reliably supports up to 10 bots and is actively maintained, with version 5 (v5) introducing significant architectural changes for improved reliability and features, including a shift to WebSocket communication.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates a basic RLBot agent that drives towards the ball. To run an RLBot, developers typically start by cloning the official `RLBot/python-example` repository, creating a Python virtual environment, installing dependencies from `requirements.txt`, and then modifying the `bot.py` file to implement their desired bot logic. The bot's `get_output` method is called every game tick to produce controller inputs.

import os
from rlbot.agents.base_agent import BaseAgent, SimpleControllerState
from rlbot.utils.structures.game_data_struct import GameTickPacket


class MyBot(BaseAgent):

    def initialize_agent(self):
        # This runs once before the bot starts.
        self.logger.log("MyBot initialized!")

    def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        # This is called every tick of the game.
        # Implement your bot's logic here.

        controller_state = SimpleControllerState()

        # Example: Drive towards the ball
        ball_location = packet.game_ball.physics.location
        my_car = packet.game_cars[self.index]
        car_location = my_car.physics.location

        # Simple steer towards the ball
        if ball_location.y > car_location.y:
            controller_state.throttle = 1.0
        else:
            controller_state.throttle = -1.0

        # Steering logic (very basic)
        if ball_location.x < car_location.x:
            controller_state.steer = -1.0
        elif ball_location.x > car_location.x:
            controller_state.steer = 1.0
        else:
            controller_state.steer = 0.0

        return controller_state


# To run this bot:
# 1. Ensure you have Rocket League installed and RLBot setup (pip install rlbot).
# 2. Typically, you'd clone an example project (e.g., RLBot/python-example),
#    place this code in its 'bot.py', and run 'python run.py' from that project's root.
#    The RLBot framework will launch Rocket League and your bot automatically.

view raw JSON →