Skip to content

Manipulating Game State

Blocks edited this page Jan 8, 2020 · 1 revision

Overview

For a general description of the feature and its possibilities, please see https://github.com/RLBot/RLBot/wiki/Manipulating-Game-State

Usage

The basic call takes this form:

GameState gameState = new GameState();
SetGameState(gameState);

You can do that from anywhere in your bot code. The above example doesn't do anything because nothing was specified on the GameState object. You can specify parts of your desired game state like this:

GameState gameState = new GameState();

CarState carState = new CarState
{
    Boost = 87f,
    PhysicsState = new PhysicsState(
        velocity: new DesiredVector3(null, null, 500),
        rotation: new DesiredRotator((float) Math.PI / 2, 0, 0),
        angularVelocity: new DesiredVector3(0, 0, 0)
    )
};
gameState.SetCarState(this.index, carState);

gameState.BallState.PhysicsState.Location = new DesiredVector3(0, 0, null);

gameState.GameInfoState.WorldGravityZ = 700f;
gameState.GameInfoState.GameSpeed = 0.8f;

SetGameState(gameState);

With the above code:

  • The bot will fling itself upward with its front pointed to the ceiling.
  • The ball will warp to the middle of the field but without altering its z position.
  • The world gravity will act weakly upwards. Note: Setting gravity to 0 will reset the gravity to normal settings. If you want to disable gravity, set the gravity to something very small like 0.0001.
  • The game's speed will be reduced to 80% of the normal speed.

A null means that the property will not be changed. For example, in the above example the ball's X and Y locations will be set to 0, but the Z will be untouched.

Warning: Setting gravity and game speed every frame will likely cause your game to lag! It is strongly recommended you only set them when required (e.g. only at the start of the game).

Taking a snapshot

Try something like GameState savedState = GameState.CreateFromGameTickPacket(gameTickPacket) to capture the current state of the ball and cars for later use! You could implement a "quicksave / quickload" type functionality with this.