-
Notifications
You must be signed in to change notification settings - Fork 87
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(jumped=False, double_jumped=False, 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.
- The game's speed will be reduced to 80% of the normal speed.
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).
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.