How to use the rlbot.utils.game_state_util.CarState function in rlbot

To help you get started, we’ve selected a few rlbot examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github samuelpmish / ExampleBots / 4_Aerial / agent.py View on Github external
def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
        self.info.read_packet(packet)
        self.controls = SimpleControllerState()

        if self.timer == 0.0:

            self.csign = random.choice([-1, 1])

            # this just initializes the car and ball
            # to different starting points each time
            c_position = Vector3(random.uniform(-1000, 1000),
                                 random.uniform(-4500, -4000),
                                 25)

            car_state = CarState(physics=Physics(
                location=c_position,
                velocity=Vector3(0, 1000, 0),
                rotation=Rotator(0, 1.5 * self.csign, 0),
                angular_velocity=Vector3(0, 0, 0)
            ))

            self.bsign = random.choice([-1, 1])

            b_position = Vector3(random.uniform(-3500, -3000) * self.bsign,
                                 random.uniform(-1500,  1500),
                                 random.uniform(  150,   500))

            b_velocity = Vector3(random.uniform( 1000, 1500) * self.bsign,
                                 random.uniform(- 500,  500),
                                 random.uniform( 1000, 1500))
github SaltieRL / Saltie / agents / self_evolving_car / train.py View on Github external
distance_to_ball_x = packet.game_ball.physics.location.x - my_car.physics.location.x
        distance_to_ball_y = packet.game_ball.physics.location.y - my_car.physics.location.y
        distance_to_ball_z = packet.game_ball.physics.location.z - my_car.physics.location.z
        self.distance_to_ball[self.frame] = math.sqrt(
            distance_to_ball_x ** 2 + distance_to_ball_y ** 2 + distance_to_ball_z ** 2)

        # render results
        action_display = "GEN: " + str(self.gen + 1) + " | BOT: " + str(self.brain)
        draw_debug(self.renderer, action_display)

        # stop evolving when ball is touched
        # if packet.game_ball.latest_touch.player_name == "Self-Evolving-Car":
        #  self.mut_rate = 0

        # game state
        car_state = CarState(boost_amount=100)
        ball_state = BallState(Physics(velocity=Vector3(0, 0, 0), location=Vector3(0, -1000, 1200),
                                       angular_velocity=Vector3(0, 0, 0)))
        game_state = GameState(ball=ball_state, cars={self.index: car_state})
        self.set_game_state(game_state)

        # neural net outputs
        with self.torch.no_grad():
            outputs = self.bot_list[self.brain].forward(*inputs)
        self.controller_state = self.output_formatter.format_model_output(outputs, [packet])[0]

        # kill
        if (my_car.physics.location.z < 100 or my_car.physics.location.z > 1950
            or my_car.physics.location.x < -4000 or my_car.physics.location.x > 4000
            or my_car.physics.location.y > 5000 or my_car.physics.location.y < -5000) \
                and self.frame > 50:
            self.frame = self.max_frames
github SaltieRL / Saltie / agents / self_evolving_car / self_evolving_car_agent.py View on Github external
def reset(self):
        # RESET TRAINING ATTRIBUTES AFTER EACH GENOME
        ball_state = BallState(Physics(velocity=Vector3(0, 0, 0), location=Vector3(self.pos, 5000, 3000),
                                       angular_velocity=Vector3(0, 0, 0)))
        car_state = CarState(jumped=False, double_jumped=False, boost_amount=33,
                             physics=Physics(velocity=Vector3(0, 0, 0), rotation=Rotator(45, 90, 0),
                                             location=Vector3(0.0, -4608, 500), angular_velocity=Vector3(0, 0, 0)))
        game_info_state = GameInfoState(game_speed=1)
        game_state = GameState(ball=ball_state, cars={self.index: car_state}, game_info=game_info_state)
        self.set_game_state(game_state)
github Darxeal / BotimusPrime / tools / state_setting.py View on Github external
def begin(self):
        self.car = CarState(Physics(Vector3(), Rotator(), Vector3(), Vector3()))
        self.opponent = CarState(Physics(Vector3(), Rotator(), Vector3(), Vector3()))
        self.ball = BallState(Physics(Vector3()))
        self.gameinfo = GameInfoState()
        self._changed = False
github samuelpmish / ExampleBots / 2_Aerial_Recovery / agent.py View on Github external
random.uniform(-3000, 3000),
                               random.uniform(  500, 2000))

            velocity = Vector3(random.uniform(-1500, 1500),
                               random.uniform(-1500, 1500),
                               random.uniform(-1000, -500))

            rotation = Rotator(random.uniform(-1.5, 1.5),
                               random.uniform(-1.5, 1.5),
                               random.uniform(-1.5, 1.5))

            angular_velocity = Vector3(random.uniform(-3.0, 3.0),
                                       random.uniform(-3.0, 3.0),
                                       random.uniform(-3.0, 3.0))

            car_state = CarState(physics=Physics(
                location=position,
                velocity=velocity,
                rotation=rotation,
                angular_velocity=angular_velocity
            ))

            self.set_game_state(GameState(cars={self.index: car_state}))

        if self.timer > 0.10:

            if self.action == None:
                self.action = AerialTurn(self.info.my_car)

            self.renderer.begin_rendering()
            red = self.renderer.create_color(255, 255, 30, 30)
            self.renderer.draw_polyline_3d(self.action.trajectory, red)
github SaltieRL / Saltie / agents / self_evolving_car / train.py View on Github external
def reset(self):
        """Resets game data after each genome"""
        ball_state = BallState(Physics(velocity=Vector3(0, 0, 0), location=Vector3(self.pos, 5000, 3000),
                                       angular_velocity=Vector3(0, 0, 0)))
        car_state = CarState(jumped=False, double_jumped=False, boost_amount=33,
                             physics=Physics(velocity=Vector3(0, 0, 0), rotation=Rotator(45, 90, 0),
                                             location=Vector3(0.0, -4608, 500), angular_velocity=Vector3(0, 0, 0)))
        game_info_state = GameInfoState(game_speed=1)
        game_state = GameState(ball=ball_state, cars={self.index: car_state}, game_info=game_info_state)
        self.set_game_state(game_state)