def debug_aim_cone(data): ball_loc = data.ball.location own_post_right, own_post_left = datalibs.get_goal_posts(data.car, data) enemy_post_right, enemy_post_left = datalibs.get_goal_posts(data.enemy, data) enemy_post_right_ang = (enemy_post_right - ball_loc).ang() enemy_post_left_ang = (enemy_post_left - ball_loc).ang() if data.car.team == 0: stress01 = rlmath.inv_lerp(datalibs.ARENA_LENGTH2, -datalibs.ARENA_LENGTH2, ball_loc.y - 500) else: stress01 = rlmath.inv_lerp(-datalibs.ARENA_LENGTH2, datalibs.ARENA_LENGTH2, ball_loc.y + 500) stress01 = min(max(0, stress01), 1) right_aim_ang = enemy_post_right_ang + 2 * stress01 left_aim_ang = enemy_post_left_ang - 2 * stress01 right_aim_ang = rlmath.fix_ang(right_aim_ang) left_aim_ang = rlmath.fix_ang(left_aim_ang) aim_cone_dyn = AimCone(right_aim_ang, left_aim_ang) aim_cone_dyn.draw(data.renderer, ball_loc, arm_count=7, b=0) car_to_ball = (ball_loc - data.car.location) good = aim_cone_dyn.contains_direction(car_to_ball) data.renderer.draw_line_3d(data.car.location.tuple(), ball_loc.tuple(), data.renderer.create_color(255, 255 if good else 0, 140 if good else 255, 0))
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 get_center_ang(self): return rlmath.fix_ang(self.right_ang - self.span_size() / 2)
def __init__(self, right_most_ang, left_most_ang): self.right_ang = rlmath.fix_ang(right_most_ang) self.left_ang = rlmath.fix_ang(left_most_ang) self.right_dir = Vec3(math.cos(right_most_ang), math.sin(right_most_ang)) self.left_dir = Vec3(math.cos(left_most_ang), math.sin(left_most_ang))
def ang_to_flat(self, ideal): current_in_radians = math.atan2(self.y, self.x) ideal_in_radians = math.atan2(ideal.y, ideal.x) diff = ideal_in_radians - current_in_radians return rlmath.fix_ang(diff)