-
Notifications
You must be signed in to change notification settings - Fork 79
Manipulating Game State
For a general description of the feature and its possibilities, please see https://github.com/RLBot/RLBot/wiki/Manipulating-Game-State
The basic call takes this form:
from rlbot.utils.game_state_util import GameState
game_state = GameState()
self.set_game_state(game_state)
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:
from rlbot.utils.game_state_util import GameState, BallState, CarState, Physics, Vector3, Rotator, GameInfoState
car_state = CarState(boost_amount=87,
physics=Physics(velocity=Vector3(z=500), rotation=Rotator(math.pi / 2, 0, 0),
angular_velocity=Vector3(0, 0, 0)))
ball_state = BallState(Physics(location=Vector3(0, 0, None)))
game_info_state = GameInfoState(world_gravity_z=700, game_speed=0.8)
game_state = GameState(ball=ball_state, cars={self.index: car_state}, game_info=game_info_state)
self.set_game_state(game_state)
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).
Also, jumped and double_jumped used to be part of the API, but they're not supported anymore and aren't coming back, sorry!
Try something like self.saved_state = GameState.create_from_gametickpacket(game_tick_packet)
to capture the current state of the ball and cars for later use! You could implement a "quicksave / quickload" type functionality with this.