def input(self): controller_input = SimpleControllerState() theta = self.current_state.rot.yaw correction_vector = self.target_state.pos - self.current_state.pos facing_vector = Vec3(cos(theta), sin(theta), 0) car_to_target = (self.target_state.pos - self.current_state.pos).normalize() #Rotated to the car's reference frame on the ground. rel_correction_vector = Vec3((correction_vector.x*cos(theta)) + (correction_vector.y * sin(theta)), (-(correction_vector.x*sin(theta))) + (correction_vector.y * cos(theta)), 0) if self.can_reverse and facing_vector.dot(car_to_target) < - 0.5: correction_angle = atan2(rel_correction_vector.y, rel_correction_vector.x) controller_input.throttle = - 1.0 if abs(correction_angle) > 1.25: controller_input.handbrake = 1 controller_input.steer = cap_magnitude(-5*correction_angle, 1) else: correction_angle = atan2(rel_correction_vector.y, rel_correction_vector.x) controller_input.throttle = 1.0 if abs(correction_angle) > 1.25: controller_input.handbrake = 1 controller_input.steer = cap_magnitude(5*correction_angle, 1) return controller_input
def resolve(self, prev_status, car, packet: GameTickPacket): point = self.pointFunc(car, packet) car_location = Vec3(car.physics.location.x, car.physics.location.y) car_direction = rlmath.get_car_facing_vector(car) yaw_velocity = car.physics.angular_velocity.x car_velocity = Vec3(car.physics.velocity.x, car.physics.velocity.y) car_to_point = point - car_location steer_correction_radians = rlmath.fix_ang( car_direction.ang_to_flat(car_to_point) + yaw_velocity * 0.2) velocity_correction_radians = car_velocity.ang_to_flat(car_to_point) controller = SimpleControllerState() if abs(steer_correction_radians) > 0.5: controller.handbrake = True else: return (SUCCESS, self.parent, None) if steer_correction_radians > 0: controller.steer = 1 elif steer_correction_radians < 0: controller.steer = -1 controller.throttle = 0.3 # In these cases we want to brake instead if car_velocity.length() > 500: controller.throttle = 0 return (ACTION, self, controller)
def controller(self, agent, angle): controller_state = SimpleControllerState() steer_value = steer(angle) controller_state.steer = steer_value controller_state.throttle = 1 controller_state.handbrake = True if self.level == PowerSlideLevel.NORMAL: balance_threshold = 0.25 * abs( agent.me.angular_velocity.data[2])**2 + 0.05 if balance_threshold * -1 <= angle <= balance_threshold: controller_state.handbrake = False controller_state.boost = True if abs(agent.me.angular_velocity.data[2]) >= 0.15: controller_state.steer = sign( agent.me.angular_velocity.data[2]) * -1 else: controller_state.steer = 0 elif self.level == PowerSlideLevel.U_TURN: if abs(angle) < 1.15: controller_state.steer = steer_value * -1 controller_state.throttle = -1 controller_state.handbrake = False controller_state.boost = False if abs(angle) < 0.15: controller_state.steer = 0 return controller_state
def CeilingRushController( agent, target_object1, target_object2): #target_object es un objeto tipo obj controller_state = SimpleControllerState() '''if distance2D(agent.me,agent.pointA)<distance2D(agent.me,agent.pointB) and agent.me.location.data[2]>2800: target_object = target_object2 location = agent.pointB.local_location angle_to_target = math.atan2(location.data[1],location.data[0]) else: target_object = target_object1 location = agent.pointA.local_location angle_to_target = math.atan2(location.data[1],location.data[0])''' target_object = target_object1 location = agent.pointA.local_location angle_to_target = math.atan2(location.data[1], location.data[0]) draw_debug(agent, agent.renderer, target_object.location.data) angle_velocity = math.atan2(agent.me.velocity.data[1], agent.me.velocity.data[1]) #draw_debug(agent.renderer,target_object.location.data) current_speed = velocity2D(agent.me) #steering if abs(angle_to_target) < math.pi / 4: controller_state.handbrake = False elif abs(angle_to_target) < math.pi and abs(angle_to_target) > math.pi / 2: controller_state.handbrake = True if agent.me.location.data[2] < 1800: controller_state.steer = sign(angle_to_target) * min( 1, abs(2 * angle_to_target)) else: controller_state.steer = 0 #throttle controller_state.throttle = 1 return controller_state
def flyController(self, agent): controller_state = SimpleControllerState() location = toLocal(agent.ball, agent.me) angle_to_target = np.arctan2(location[1], location[0]) location_of_target = toLocal(agent.ball, agent.me) '''steering''' if angle_to_target > .1: controller_state.steer = 1 #controller_state.yaw = 1 controller_state.throttle = 1 if distance2D(agent.ball, agent.me) < 1000: controller_state.boost = True elif angle_to_target < -.1: controller_state.steer = -1 #controller_state.yaw = -1 controller_state.throttle = 1 if distance2D(agent.ball, agent.me) < 1000: controller_state.boost = True else: controller_state.steer = controller_state.yaw = 0 controller_state.throttle = .5 if angle_to_target < .1 and angle_to_target > -.1: controller_state.boost = True else: controller_state.boost = False #jump time_difference = time.time() - agent.start if time_difference > 2.2: agent.start = time.time() elif time_difference < .1 and distance2D( agent.ball, agent.me) < 1000 and agent.ball.location[2] > 100: controller_state.jump = True print("jump") else: controller_state.jump = False if agent.ball.location[2] > agent.me.location[ 2] and agent.me.rotation[0] < verticalangle2D( agent.ball.local_location, agent.me) and agent.me.rotation[1] < angle_to_radians( 0): #change angle, this is wrong controller_state.pitch = 1 # nose up elif agent.ball.location[2] < agent.me.location[ 2] and agent.me.rotation[0] > verticalangle2D( agent.ball.local_location, agent.me) and agent.me.rotation[1] > angle_to_radians(0): controller_state.pitch = -1 # nose down #updated code broke this # if(agent.ball.location[2] > agent.me.location[2]): # print("ball above car", verticalangle2D(agent.ball.local_location, agent.me)*180/np.pi) # if(agent.ball.location[2] < agent.me.location[2]): # print("ball below car", verticalangle2D(agent.ball.local_location, agent.me)*180/np.pi) return (controller_state)
def diagonal(game_info=None, x_sign=None, persistent=None): current_state = game_info.me controls = SimpleControllerState() #Set which boost we want based on team and side. if x_sign == -1: first_boost = 11 else: first_boost = 10 if game_info.boosts[first_boost].is_active: #If we haven't taken the small boost yet, drive towards it controls = GroundTurn( current_state, current_state.copy_state(pos=Vec3(0, -1000, 0))).input() controls.boost = 1 elif abs(current_state.pos.y) > 1100 and current_state.wheel_contact: controls.jump = 1 controls.boost = 1 elif abs(current_state.pos.y) > 1100 and current_state.pos.z < 40: controls.jump = 1 controls.boost = 1 elif abs(current_state.pos.y) > 500 and not current_state.double_jumped: controls = CancelledFastDodge(current_state, Vec3(1, x_sign, 0)).input() elif abs(current_state.pos.y) > 250 and not current_state.wheel_contact: if persistent.aerial_turn.action == None: persistent.aerial_turn.initialize = True target_rot = Orientation(pitch=pi / 3, yaw=current_state.rot.yaw, roll=0) persistent.aerial_turn.target_orientation = target_rot else: controls, persistent = aerial_rotation(game_info.dt, persistent) controls.boost = 1 controls.steer = x_sign #Turn into the ball elif abs(current_state.pos.y) > 235: controls.throttle = 1 controls.boost = 1 controls.steer = x_sign else: controls = FrontDodge(current_state).input() return controls, persistent
def get_output(self, game_tick_packet: GameTickPacket) -> SimpleControllerState: seconds = game_tick_packet.game_info.seconds_elapsed controller_state = SimpleControllerState() controller_state.steer = 0 controller_state.handbrake = 0 return controller_state
def waitController(agent, target, speed): controller_state = SimpleControllerState() loc = toLocal(target, agent.me) angle_to_target = math.atan2(loc.data[1], loc.data[0]) controller_state.steer = steer(angle_to_target) current_speed = velocity2D(agent.me) if current_speed < speed: controller_state.throttle = 1.0 elif current_speed - 50 > speed: controller_state.throttle = -1.0 else: controller_state.throttle = 0 time_diff = time.time() - agent.start if time_diff > 2.2 and distance2D(target,agent.me) > (velocity2D(agent.me)*2.3) and abs(angle_to_target) < 1 and current_speed < speed: agent.start = time.time() elif time_diff <= 0.1: controller_state.jump = True controller_state.pitch = -1 elif time_diff >= 0.1 and time_diff <= 0.15: controller_state.jump = False controller_state.pitch = -1 elif time_diff > 0.15 and time_diff < 1: controller_state.jump = True controller_state.yaw = controller_state.steer controller_state.pitch = -1 return controller_state
def exampleController(agent, target_object,target_speed): distance = distance2D(agent.me.location,target_object.location) if distance > 400: #print("switching to efficient") agent.state = efficientMover return efficientMover(agent,target_object,target_speed) controller_state = SimpleControllerState() controller_state.handbrake = False car_direction = get_car_facing_vector(agent.me) car_to_ball = agent.me.location - target_object.location steer_correction_radians = steer(car_direction.correction_to(car_to_ball)) current_speed = getVelocity(agent.me.velocity) #steering controller_state.steer = steer(steer_correction_radians) #throttle if target_speed > current_speed: controller_state.throttle = 1.0 if target_speed > 1400 and current_speed < 2250: controller_state.boost = True elif target_speed < current_speed: controller_state.throttle = 0 return controller_state
def exampleController(agent, target_object): #target_object es un objeto tipo obj location = target_object.local_location controller_state = SimpleControllerState() angle_to_target = math.atan2(location.data[1], location.data[0]) angle_velocity = math.atan2(agent.me.velocity.data[1], agent.me.velocity.data[1]) #draw_debug(agent.renderer,location.data) draw_debug(agent, agent.renderer, target_object.location.data) current_speed = velocity2D(agent.me) #steering if abs(angle_to_target) < math.pi / 4: if agent.me.has_wheel_contact == True: controller_state.boost = True controller_state.handbrake = False else: controller_state.boost = False controller_state.handbrake = True controller_state.steer = sign(angle_to_target) * min( 1, abs(2 * angle_to_target)) controller_state.throttle = 1 #dodging if abs(angle_to_target) < math.pi / 2 and abs( angle_velocity) < math.pi / 3: dodging(agent, target_object, controller_state, angle_to_target) return controller_state
def frugal_controller(agent, target, speed): controller_state = SimpleControllerState() location = return_local_location(target, agent.me) angle_to_target = math.atan2(location.data[1], location.data[0]) controller_state.steer = steer(angle_to_target) current_speed = velocity_2d(agent.me) if current_speed < speed: controller_state.throttle = 1.0 elif current_speed - 50 > speed: controller_state.throttle = -1.0 else: controller_state.throttle = 0 if distance_2d(agent.me.location.data, target) < 250: controller_state.handbrake = 1 # time_difference = time.time() - agent.start # if time_difference > 2.2 and distance_2d(target, agent.me) > (velocity_2d(agent.me) * 2.3) and abs( # angle_to_target) < 1 and current_speed < speed: # agent.start = time.time() # elif time_difference <= 0.1: # controller_state.jump = True # controller_state.pitch = -1 # elif time_difference >= 0.1 and time_difference <= 0.15: # controller_state.jump = False # controller_state.pitch = -1 # elif time_difference > 0.15 and time_difference < 1: # controller_state.jump = True # controller_state.yaw = controller_state.steer # controller_state.pitch = -1 return controller_state
def pid_steer(game_info, target_location, pid: SteerPID): """Gives a set of commands to move the car along the ground toward a target location Attributes: target_location (Vec3): The local location the car wants to aim for Returns: SimpleControllerState: the set of commands to achieve the goal """ controller_state = SimpleControllerState() ball_direction = target_location angle = -np.arctan2(ball_direction.y, ball_direction.x) if angle > np.pi: angle -= 2 * np.pi elif angle < -np.pi: angle += 2 * np.pi # adjust angle turn_rate = pid.get_steer(angle) controller_state.throttle = 1 controller_state.steer = turn_rate controller_state.jump = False return controller_state
def get_output(self, game_tick_packet: GameTickPacket) -> SimpleControllerState: # Get the direction to the ball car = game_tick_packet.game_cars[self.index] ball_pos = game_tick_packet.game_ball.physics.location to_ball_x = ball_pos.x - car.physics.location.x to_ball_y = ball_pos.y - car.physics.location.y dist_to_ball = math.sqrt(to_ball_x**2 + to_ball_y**2) if dist_to_ball == 0: return SimpleControllerState() to_ball_x /= dist_to_ball to_ball_y /= dist_to_ball # How is the car aligned with the direction to the ball? yaw = float(car.physics.rotation.yaw) car_left_x = -math.sin(yaw) car_left_y = math.cos(yaw) dot_product = to_ball_x * car_left_x + to_ball_y * car_left_y # Act on the information above. controller_state = SimpleControllerState() controller_state.throttle = 1.0 controller_state.steer = min( 1, max(-1, self.steering_coefficient * dot_product)) controller_state.boost = abs(dot_product) < .1 controller_state.handbrake = abs(dot_product) > .9 return controller_state
def frugalController(agent, target, speed): controller_state = SimpleControllerState() location = toLocal(target, agent.me) angle_to_target = math.atan2(location.data[1], location.data[0]) controller_state.steer = steer(angle_to_target) speed -= ((angle_to_target**2) * 300) current_speed = velocity1D(agent.me).data[1] if current_speed < speed: controller_state.throttle = 1.0 elif current_speed - 50 > speed: controller_state.throttle = -1.0 else: controller_state.throttle = 0 time_difference = time.time() - agent.start if time_difference > 2.2 and distance2D( target, agent.me) > (velocity2D(agent.me) * 2.3) and abs( angle_to_target ) < 0.9 and current_speed < speed and current_speed > 220: agent.start = time.time() elif time_difference <= 0.1: controller_state.jump = True controller_state.pitch = -1 elif time_difference >= 0.1 and time_difference <= 0.15: controller_state.jump = False controller_state.pitch = -1 elif time_difference > 0.15 and time_difference < 1: controller_state.jump = True controller_state.yaw = controller_state.steer controller_state.pitch = -1 return controller_state
def go_nuts(gi: GameInfo) -> Sequence: ball_location = Vec3(gi.packet.game_ball.physics.location) if gi.car.location.flat().dist(ball_location.flat()) > 2000: # We're far away from the ball, let's try to lead it a little bit ball_prediction = gi.bot.get_ball_prediction_struct() # This can predict bounces, etc ball_in_future_location = Vec3(find_slice_at_time(ball_prediction, gi.packet.game_info.seconds_elapsed + 2).physics.location) target_location = ball_in_future_location.flat() + (ball_in_future_location.flat() - Vec3(gi.field.opponent_goal.location)).rescale(2200).flat() with Renderer(gi.bot.renderer) as r: r.draw_line_3d(ball_location, target_location, r.cyan()) else: target_location = ball_location + (ball_location - Vec3(gi.field.opponent_goal.location)).rescale(100) # Draw some things to help understand what the bot is thinking with Renderer(gi.bot.renderer) as r: r.draw_line_3d(gi.car.location, target_location, r.white()) r.draw_string_3d(gi.car.location, 1, 1, f'Speed: {gi.car.velocity.length():.1f}', r.white()) r.draw_rect_3d(target_location, 8, 8, True, r.cyan(), centered=True) controls = SimpleControllerState() controls.steer = gi.car.steer_toward_target(target_location) controls.throttle = 1.0 controls.boost = abs(controls.steer) < 0.2 and gi.car.velocity.length() < 2000 # controls.handbrake = abs(controls.steer) > 0.99 and gi.car.location.dist(ball_location) > 1000 return Sequence([SingleStep(controls)])
def deltaC( info: Info, target: Vector3, jt ): # this controller takes a vector containing the required acceleration to reach a target, and then gets the car there c = SimpleControllerState() target_local = info.car_matrix.dot(target) if info.car.has_wheel_contact: # if on the ground if jt + 1.5 > info.game_time: # if we haven't jumped in the last 1.5 seconds c.jump = True else: c.jump = False jt = info.game_time else: c.steer, c.yaw, c.pitch, c.roll, error = default_pd(info, target_local, True) if target.length > 25: # stops boosting when "close enough" c.boost = True if error > 0.9: # don't boost if we're not facing the right way c.boost = False tsj = info.game_time - jt # time since jump if tsj < 0.215: c.jump = True elif tsj < 0.25: c.jump = False elif ( tsj >= 0.25 and tsj < 0.27 and target.z > 560 ): # considers a double-jump if we still need to go up a lot c.jump = True c.boost = False c.yaw = c.pitch = c.roll = 0 else: c.jump = False c.throttle = 1 return c, jt
def action_goto(self, my_car, car_location, target_location): controller = SimpleControllerState() if target_location is None: return controller car_to_target = target_location - car_location # Find the direction of our car using the Orientation class car_orientation = Orientation(my_car.physics.rotation) car_direction = car_orientation.forward steer_correction_radians = find_correction(car_direction, car_to_target) if steer_correction_radians > 0: # Positive radians in the unit circle is a turn to the left. turn = -1.0 # Negative value for a turn to the left. self.action_display = "turn left" else: turn = 1.0 self.action_display = "turn right" controller.throttle = 1.0 controller.steer = turn controller.boost = True return controller
def input(self): controller_input = SimpleControllerState() current_angle_vec = Vec3(cos(self.current_state.rot.yaw), sin(self.current_state.rot.yaw), 0) goal_angle_vec = Vec3(cos(self.goal_state.rot.yaw), sin(self.goal_state.rot.yaw), 0) vel_2d = Vec3(self.current_state.vel.x, self.current_state.vel.y, 0) if (self.current_state.pos - self.goal_state.pos).magnitude() > 400: #Turn towards target. Hold throttle until we're close enough to start stopping. controller_input = GroundTurn(self.current_state, self.goal_state).input() elif vel_2d.magnitude() < 50 and current_angle_vec.dot(goal_angle_vec) < 0: #If we're moving slowly, but not facing the right way, jump to turn in the air. #Decide which way to turn. Make sure we don't have wraparound issues. goal_x = goal_angle_vec.x goal_y = goal_angle_vec.y car_theta = self.current_state.rot.yaw #Rotated to the car's reference frame on the ground. rel_vector = Vec3((goal_x*cos(car_theta)) + (goal_y * sin(car_theta)), (-(goal_x*sin(car_theta))) + (goal_y * cos(car_theta)), 0) correction_angle = atan2(rel_vector.y, rel_vector.x) #Jump and turn to reach goal yaw. if self.current_state.wheel_contact: controller_input.jump = 1 else: controller_input.yaw = cap_magnitude(correction_angle, 1) elif self.current_state.vel.magnitude() > 400: #TODO: Proportional controller to stop in the right place controller_input.throttle = -1 else: #Wiggle to face ball #Check if the goal is ahead of or behind us, and throttle in that direction goal_angle = atan2((self.goal_state.pos - self.current_state.pos).y, (self.goal_state.pos - self.current_state.pos).x) if abs(angle_difference(goal_angle,self.current_state.rot.yaw)) > pi/2: correction_sign = -1 else: correction_sign = 1 controller_input.throttle = correction_sign #Correct as we wiggle so that we face goal_yaw. if angle_difference(self.goal_state.rot.yaw, self.current_state.rot.yaw) > 0: angle_sign = 1 else: angle_sign = -1 controller_input.steer = correction_sign*angle_sign return controller_input
def exampleController(agent, target_object, target_speed): location = toLocal(target_object, agent.me) controller_state = SimpleControllerState() angle_to_ball = math.atan2(location.data[1], location.data[0]) current_speed = velocity2D(agent.me) #steering controller_state.steer = steer(angle_to_ball) #throttle if target_speed > current_speed: controller_state.throttle = 1.0 if target_speed > 1400 and agent.start > 2.2 and current_speed < 2250: controller_state.boost = True elif target_speed < current_speed: controller_state.throttle = 0 #dodging time_difference = time.time() - agent.start if time_difference > 2.2 and distance2D(target_object, agent.me) > ( velocity2D(agent.me) * 2.5) and abs(angle_to_ball) < 1.3: agent.start = time.time() elif time_difference <= 0.1: controller_state.jump = True controller_state.pitch = -1 elif time_difference >= 0.1 and time_difference <= 0.15: controller_state.jump = False controller_state.pitch = -1 elif time_difference > 0.15 and time_difference < 1: controller_state.jump = True controller_state.yaw = controller_state.steer controller_state.pitch = -1 return controller_state
def get_output(self, game_tick_packet: GameTickPacket) -> SimpleControllerState: controller_state = SimpleControllerState() controller_state.throttle = 1 controller_state.boost = True controller_state.steer = -1 if int(game_tick_packet.game_info.seconds_elapsed) % 2 == 0 else 1 self.renderer.draw_line_3d((0, 0, 50), (0, 0, 2000), self.renderer.orange()) return controller_state
def get_output(self, game_tick_packet: GameTickPacket) -> SimpleControllerState: controller_state = SimpleControllerState() if not game_tick_packet.game_info.is_round_active: return controller_state ball_location = Vector2(game_tick_packet.game_ball.physics.location.x, game_tick_packet.game_ball.physics.location.y) my_car = game_tick_packet.game_cars[self.index] car_location = Vector2(my_car.physics.location.x, my_car.physics.location.y) car_direction = get_car_facing_vector(my_car) car_to_ball = ball_location - car_location steer_correction_radians = car_direction.correction_to(car_to_ball) if steer_correction_radians > 0: # Positive radians in the unit circle is a turn to the left. turn = -1.0 # Negative value for a turn to the left. else: turn = 1.0 if self.flip_turning: turn *= -1.0 if turn == -1.0 and self.test_quickchat: self.send_quick_chat(QuickChats.CHAT_EVERYONE, QuickChats.Information_IGotIt) if self.test_rendering: self.do_rendering_test(game_tick_packet, my_car) if self.test_dropshot: self.do_dropshot_tile_test(game_tick_packet) if self.test_state: self.set_state_test(game_tick_packet) if self.test_ball_prediction: self.render_ball_prediction() if self.test_physics_tick: self.do_physics_tick_test(game_tick_packet) controller_state.throttle = 1.0 controller_state.steer = turn return self.convert_output_to_v4([ 1.0, # throttle turn, # steer 0.0, # pitch 0.0, # yaw 0.0, # roll 0, # jump 0, # boost 0 # handbrake ])
def move_towards_point(self, my_car, point, boost: bool) -> SimpleControllerState: # Set the final controls based off of above decision making controls = SimpleControllerState() controls.steer = steer_toward_target(my_car, point) controls.throttle = 1.0 if boost: controls.boost = True return controls
def input(self): controller_input = SimpleControllerState() controller_input.throttle = 1 if self.boost == 1: controller_input.boost = 1 controller_input.handbrake = 1 controller_input.steer = self.direction return controller_input
def hermite_update(fieldstate): spline_pos, spline_d = h_spline.get( fieldstate.elapsed_time() - spline_start, spline_scale) goal_position = spline_pos error_vector = goal_position - fieldstate.car_location() correction_angle = fieldstate.car_facing_vector().correction_to( error_vector) goal_velocity = spline_d goal_angle = fieldstate.car_facing_vector().correction_to(spline_d) output = SimpleControllerState() #velocity PID vel_pid_out = vel_pid.update(goal_velocity.length(), fieldstate.car_velocity().length(), fieldstate.delta_time()) position_pid_out = position_pid.update(error_vector.length(), 0, fieldstate.delta_time()) output.throttle = clamp(vel_pid_out + position_pid_out, 1.0, -1.0) #heading PID heading_pid_out = heading_pid.update(-goal_angle * sign(output.throttle), 0, fieldstate.delta_time()) heading_abs_pid_out = heading_abs_pid.update( -correction_angle * sign(output.throttle), 0, fieldstate.delta_time()) output.steer = clamp(heading_pid_out + heading_abs_pid_out, 1.0, -1.0) # fi.write("{},{},{},{},{},{},{},{},{},{},{},{},{},{},{},{}\n".format( # fieldstate.elapsed_time(), # error_vector.length() * sign(Vector3.dot(error_vector, fieldstate.car_facing_vector().normalize())), # goal_position.x, # goal_position.y, # fieldstate.car_location().x, # fieldstate.car_location().y, # goal_velocity.length(), # fieldstate.car_velocity().length(), # math.atan2(spline_d.y, spline_d.x), # math.atan2(fieldstate.car_facing_vector().y, fieldstate.car_facing_vector().x), # vel_pid_out, # position_pid_out, # heading_pid_out, # heading_abs_pid_out, # output.throttle, # output.steer # )) if goal_velocity.length() > 1400: output.boost = True return output
def ground_controller(game_info, target_location): """Gives a set of commands to move the car along the ground toward a target location Attributes: target_location (Vec3): The local location the car wants to aim for Returns: SimpleControllerState: the set of commands to achieve the goal """ controller_state = SimpleControllerState() ball_direction = target_location distance = target_location.flat().length() angle = -math.atan2(ball_direction.y, ball_direction.x) if angle > math.pi: angle -= 2*math.pi elif angle < -math.pi: angle += 2*math.pi speed = 0.0 turn_rate = 0.0 r1 = 250 r2 = 1000 # adjust angle if angle > 0.02: turn_rate = -1.0 elif angle < -0.02: turn_rate = 1.0 else: turn_rate = 0 if distance <= r1: # if toward ball move forward if abs(angle) < math.pi / 4: speed = 1.0 else: # if not toward ball reverse, flips turn rate to adjust turn_rate = turn_rate * -1.0 speed = -1.0 # if far away, move at full speed forward elif distance >= r2: speed = 1.0 if game_info.me.velocity.length() < 2250: controller_state.boost = True # if mid range, adjust forward else: # adjust speed if game_info.me.velocity.length() < 2250: controller_state.boost = True if abs(angle) < math.pi / 2: speed = 1.0 else: speed = 0.5 controller_state.throttle = speed controller_state.steer = turn_rate controller_state.jump = False return controller_state
def get_output(self, packet: GameTickPacket) -> SimpleControllerState: bot = PhysicsObject(packet.game_cars[self.agent.index].physics) steer = steering.simple_aim(bot.location, bot.rotation.z, self.target) controller = SimpleControllerState() controller.steer = steer controller.throttle = 1 return controller
def get_controls(game_info, sub_state_machine): controls = SimpleControllerState() controls.throttle = 1 controls.boost = 1 controls.steer = -1 persistent = game_info.persistent return controls, persistent
def to_simple_controller_state(self): controls = SimpleControllerState() controls.throttle = self.throttle controls.steer = self.steer controls.yaw = self.yaw controls.pitch = self.pitch controls.roll = self.roll controls.boost = self.boost controls.jump = self.jump controls.handbrake = self.handbrake return controls
def get_controls(game_info, sub_state_machine): controls = SimpleControllerState() persistent = game_info.persistent persistent.aerial_turn.action.step(game_info.dt) controls = persistent.aerial_turn.action.controls controls.boost = 1 controls.steer = 1 return controls, persistent
def goto(target_location, target_speed, my_car, agent, packet): car_speed = Vec3(my_car.physics.velocity).length() distance = Vec3(my_car.physics.location).flat().dist( target_location.flat()) angle = Orientation( my_car.physics.rotation).forward.ang_to(target_location - Vec3(my_car.physics.location)) controls = SimpleControllerState() controls.steer = steer_toward_target(my_car, target_location, 0) controls.yaw = steer_toward_target(my_car, target_location, -my_car.physics.angular_velocity.z / 6) controls.throttle = cap(target_speed - car_speed, -1, 1) controls.boost = (target_speed > 1410 and abs(target_speed - car_speed) > 20 and angle < 0.3) controls.handbrake = angle > 2.3 controls.jump = (1 if my_car.physics.location.y >= 0 else -1) == ( 1 if agent.team == 1 else -1 ) and abs( my_car.physics.location.y) > 5000 and my_car.physics.location.z > 200 controls.use_item = Vec3(my_car.physics.location).dist( Vec3(packet.game_ball.physics.location)) < 200 and relative_location( Vec3(my_car.physics.location), Orientation( my_car.physics.rotation), Vec3(packet.game_ball.physics.location)).z < 75 if (abs(target_speed - car_speed) > 20 and angle < 0.3 and distance > 600) and ((target_speed > 1410 and my_car.boost == 0) or 700 < car_speed < 800): agent.stack.append(wavedash(target_location)) return controls