def update_controls(self, controls: PlayerInput): air_roll = self.button_data[2] or self.button_data[9] controls.throttle = self.axis_data[5] - self.axis_data[4] controls.steer = self.axis_data[0] controls.pitch = self.axis_data[1] controls.yaw = 0 if air_roll else self.axis_data[0] controls.roll = self.axis_data[0] if air_roll else 0 controls.jump = self.button_data[0] controls.boost = self.button_data[1] controls.handbrake = air_roll
def get_player_input(self) -> PlayerInput: player_input = PlayerInput() player_input.throttle = self.controls.throttle player_input.steer = self.controls.steer player_input.pitch = self.controls.pitch player_input.yaw = self.controls.yaw player_input.roll = self.controls.roll player_input.jump = self.controls.jump player_input.boost = self.controls.boost player_input.handbrake = self.controls.handbrake return player_input
def convert_player_input(ctrl: SimpleControllerState) -> PlayerInput: """ Converts a SimpleControllerState to a PlayerInput object. """ player_input = PlayerInput() player_input.throttle = ctrl.throttle player_input.steer = ctrl.steer player_input.pitch = ctrl.pitch player_input.yaw = ctrl.yaw player_input.roll = ctrl.roll player_input.jump = ctrl.jump player_input.boost = ctrl.boost player_input.handbrake = ctrl.handbrake player_input.use_item = ctrl.use_item return player_input
def get_player_input(self) -> PlayerInput: """"Get the current controls from the drone. :return: Current controls for this car. :rtype: PlayerInput """ # Throw error if no controls were set. if self.controller is None: RuntimeError(f"Did not set the controls for drone {self.index}") # PlayerInput mapping player_input = PlayerInput() player_input.throttle = self.controller.throttle # -1 for full reverse, 1 for full forward player_input.steer = self.controller.steer # -1 for full left, 1 for full right player_input.pitch = self.controller.pitch # -1 for nose down, 1 for nose up player_input.yaw = self.controller.yaw # -1 for full left, 1 for full right player_input.roll = self.controller.roll # -1 for roll left, 1 for roll right player_input.jump = self.controller.jump # true if you want to press the jump button player_input.boost = self.controller.boost # true if you want to press the boost button player_input.handbrake = self.controller.handbrake # true if you want to press the handbrake button return player_input
def spawn_car_in_showroom(loadout_config: LoadoutConfig, team: int, showcase_type: str, map_name: str, launcher_prefs: RocketLeagueLauncherPreference): match_config = MatchConfig() match_config.game_mode = 'Soccer' match_config.game_map = map_name match_config.instant_start = True match_config.existing_match_behavior = 'Continue And Spawn' match_config.networking_role = NetworkingRole.none match_config.enable_state_setting = True match_config.skip_replays = True bot_config = PlayerConfig() bot_config.bot = True bot_config.rlbot_controlled = True bot_config.team = team bot_config.name = "Showroom" bot_config.loadout_config = loadout_config match_config.player_configs = [bot_config] match_config.mutators = MutatorConfig() match_config.mutators.boost_amount = 'Unlimited' match_config.mutators.match_length = 'Unlimited' global sm if sm is None: sm = SetupManager() sm.connect_to_game(launcher_preference=launcher_prefs) sm.load_match_config(match_config) sm.start_match() game_state = GameState( cars={0: CarState(physics=Physics( location=Vector3(0, 0, 20), velocity=Vector3(0, 0, 0), angular_velocity=Vector3(0, 0, 0), rotation=Rotator(0, 0, 0) ))}, ball=BallState(physics=Physics( location=Vector3(0, 0, -100), velocity=Vector3(0, 0, 0), angular_velocity=Vector3(0, 0, 0) )) ) player_input = PlayerInput() team_sign = -1 if team == 0 else 1 if showcase_type == "boost": player_input.boost = True player_input.steer = 1 game_state.cars[0].physics.location.y = -1140 game_state.cars[0].physics.velocity.x = 2300 game_state.cars[0].physics.angular_velocity.z = 3.5 elif showcase_type == "throttle": player_input.throttle = 1 player_input.steer = 0.56 game_state.cars[0].physics.location.y = -1140 game_state.cars[0].physics.velocity.x = 1410 game_state.cars[0].physics.angular_velocity.z = 1.5 elif showcase_type == "back-center-kickoff": game_state.cars[0].physics.location.y = 4608 * team_sign game_state.cars[0].physics.rotation.yaw = -0.5 * pi * team_sign elif showcase_type == "goal-explosion": game_state.cars[0].physics.location.y = -2000 * team_sign game_state.cars[0].physics.rotation.yaw = -0.5 * pi * team_sign game_state.cars[0].physics.velocity.y = -2300 * team_sign game_state.ball.physics.location = Vector3(0, -3500 * team_sign, 93) sm.game_interface.update_player_input(player_input, 0) sm.game_interface.set_game_state(game_state)