Skip to content

Manipulating Game State

Eric Veilleux edited this page Feb 2, 2025 · 2 revisions

Usage

The basic call takes this form:

# ...

self.set_game_state()

# ...

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

from rlbot.flat import DesiredBallState, DesiredCarState, DesiredMatchInfo, DesiredPhysics, RotatorPartial, Vector3Partial

car_state = DesiredCarState(
    boost_amount=87, 
    physics=Physics(
        velocity=Vector3(z=500),
        rotation=Rotator(math.pi / 2, 0, 0),
        angular_velocity=Vector3(0, 0, 0)
    )
)

ball_state = DesiredBallState(Physics(location=Vector3(0, 0, None)))

match_info = DesiredMatchInfo(world_gravity_z=700, game_speed=0.8)

self.set_game_state(balls={0: ball_state}, cars={self.index: car_state}, game_info=match_info)

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 None 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).

Clone this wiki locally