def align(self, bot, target_rot: Mat33) -> SimpleControllerState: car = bot.info.my_car local_forward = dot(target_rot.col(0), car.rot) local_up = dot(target_rot.col(2), car.rot) local_ang_vel = dot(car.ang_vel, car.rot) pitch_ang = math.atan2(-local_forward.z, local_forward.x) pitch_ang_vel = local_ang_vel.y yaw_ang = math.atan2(-local_forward.y, local_forward.x) yaw_ang_vel = -local_ang_vel.z roll_ang = math.atan2(-local_up.y, local_up.z) roll_ang_vel = local_ang_vel.x forwards_dot = dot(target_rot.col(0), car.forward) roll_scale = forwards_dot**2 if forwards_dot > 0.85 else 0 self.controls.pitch = clip(-3.3 * pitch_ang + 0.8 * pitch_ang_vel, -1, 1) self.controls.yaw = clip(-3.3 * yaw_ang + 0.9 * yaw_ang_vel, -1, 1) self.controls.roll = clip(-3 * roll_ang + 0.5 * roll_ang_vel, -1, 1) * roll_scale self.controls.throttle = 1 return self.controls
def find_landing_orientation(car: Car) -> Mat33: # FIXME: This uses a cheap approximation of the walls to find landing orientation obj = DummyObject(car) prev_pos = obj.pos for i in range(100): predict.fall(obj, 0.1) # Checking for intersections for plane in Field.SIDE_WALLS_AND_GROUND: if intersects_plane(prev_pos, obj.pos, plane): # Bingo! fall_dir = normalize(obj.pos - prev_pos) left = -cross(fall_dir, plane.normal) forward = -cross(plane.normal, left) return Mat33.from_columns(forward, left, plane.normal) prev_pos = obj.pos # No wall/ground intersections found in fall # Default to looking in direction of velocity, but upright forward = normalize(xy( car.vel)) if norm(xy(car.vel)) > 20 else car.forward up = Vec3(z=1) left = cross(up, forward) return Mat33.from_columns(forward, left, up)
def __init__(self, index=-1, name="Unknown", team=0, pos=Vec3(), vel=Vec3(), ang_vel=Vec3(), rot=Mat33(), time=0.0): self.id = index self.name = name self.team = team self.pos = pos self.vel = vel self.rot = rot self.ang_vel = ang_vel self.time = time self.is_demolished = False self.jumped = False self.double_jumped = False self.on_ground = True self.supersonic = False self.last_expected_time_till_reach_ball = 3 self.last_input = SimpleControllerState()
def find_landing_orientation(car: Car, num_points: int) -> Mat33: """ dummy = DummyObject(car) trajectory = [Vec3(dummy.pos)] for i in range(0, num_points): fall(dummy, 0.0333) # Apply physics and let car fall through the air trajectory.append(Vec3(dummy.pos)) up = dummy.pitch_surface_normal() if norm(up) > 0.0 and i > 10: up = normalize(up) forward = normalize(dummy.vel - dot(dummy.vel, up) * up) left = cross(up, forward) return Mat33.from_columns(forward, left, up) return Mat33(car.rot) """ forward = normalize(xy( car.vel)) if norm(xy(car.vel)) > 20 else car.forward up = Vec3(z=1) left = cross(up, forward) return Mat33.from_columns(forward, left, up)
def find_landing_orientation(car: Car) -> Mat33: # FIXME: If we knew the arena's mesh we could test if we are landing on a wall or something forward = normalize(xy( car.vel)) if norm(xy(car.vel)) > 20 else car.forward up = Vec3(z=1) left = cross(up, forward) return Mat33.from_columns(forward, left, up)
def find_landing_orientation(car: Car, num_points: int) -> Mat33: dummy = DummyObject(car) for i in range(0, num_points): fall(dummy, 0.0333) # Apply physics and let car fall through the air if i > 5 and sdf_contains(dummy.pos): up = normalize(sdf_normal(dummy.pos)) left = cross(normalize(dummy.vel), up) forward = cross(up, left) return Mat33.from_columns(forward, left, up) forward = normalize(xy( car.vel)) if norm(xy(car.vel)) > 20 else car.forward up = Vec3(z=1) left = cross(up, forward) return Mat33.from_columns(forward, left, up)
def __init__(self, index=-1, name="Unknown", team=0, pos=Vec3(), vel=Vec3(), ang_vel=Vec3(), rot=Mat33(), time=0.0): self.id = index self.name = name self.team = team self.team_sign = -1 if team == 0 else 1 self.pos = pos self.vel = vel self.rot = rot self.ang_vel = ang_vel self.time = time self.is_demolished = False self.jumped = False self.double_jumped = False self.on_ground = True self.supersonic = False self.last_quick_chat = None self.last_expected_time_till_reach_ball = 3 self.last_input = SimpleControllerState() # Analytic info self.effective_pos = pos # A point a bit in front of them self.objective = Objective.UNKNOWN self.possession = 0 self.onsite = False self.reach_ball_time = 0 self.last_ball_touch = 0.0