def simulate_landing(self): dummy = Car(self.car) self.trajectory = [vec3(dummy.position)] self.landing = False collision_normal: Optional[vec3] = None dt = 1 / 60 simulation_duration = 0.8 for i in range(int(simulation_duration / dt)): dummy.step(Input(), dt) self.trajectory.append(vec3(dummy.position)) collision_sphere = sphere(dummy.position, 50) collision_ray = Field.collide(collision_sphere) collision_normal = collision_ray.direction if (norm(collision_normal) > 0.0 or dummy.position[2] < 0) and i > 20: self.landing = True self.landing_pos = dummy.position break if self.landing: u = collision_normal f = normalize(dummy.velocity - dot(dummy.velocity, u) * u) l = normalize(cross(u, f)) self.aerial_turn.target = mat3(f[0], l[0], u[0], f[1], l[1], u[1], f[2], l[2], u[2]) else: target_direction = normalize( normalize(self.car.velocity) - vec3(0, 0, 3)) self.aerial_turn.target = look_at(target_direction, vec3(0, 0, 1))
def __init__(self, car: Car, info: Game): self.turn = AerialTurn(car) self.target = None self.car: Car = car self.info: Game = info self.controls = Input() self.jump = False
def __init__(self, car, ball, goal): self.car = car self.ball = ball self.goal = goal self.controls = Input() self.p_s = 0 self.finished = False
def __init__(self, duration): self.duration = duration self.controls = Input() self.timer = 0 self.counter = 0 self.finished = False
def get_output(self, packet: GameTickPacket): # wait a few ticks after initialization, so we work correctly in rlbottraining if self.tick_counter < 20: self.tick_counter += 1 return Input() self.info.read_packet(packet) # cancel maneuver if a kickoff is happening and current maneuver isn't a kickoff maneuver if packet.game_info.is_kickoff_pause and not isinstance( self.maneuver, Kickoff): self.maneuver = None # reset maneuver when another car hits the ball touch = packet.game_ball.latest_touch if (touch.time_seconds > self.last_latest_touch_time and touch.player_name != packet.game_cars[self.index].name): self.last_latest_touch_time = touch.time_seconds # don't reset when we're dodging, wavedashing or recovering if self.maneuver and self.maneuver.interruptible(): self.maneuver = None # choose maneuver if self.maneuver is None: if self.RENDERING: self.draw.clear() if self.info.get_teammates(self.info.cars[self.index]): self.maneuver = teamplay_strategy.choose_maneuver( self.info, self.info.cars[self.index]) else: self.maneuver = solo_strategy.choose_maneuver( self.info, self.info.cars[self.index]) # execute maneuver if self.maneuver is not None: self.maneuver.step(self.info.time_delta) self.controls = self.maneuver.controls if self.RENDERING: self.draw.group("maneuver") self.draw.color(self.draw.yellow) self.draw.string( self.info.cars[self.index].position + vec3(0, 0, 50), type(self.maneuver).__name__) self.maneuver.render(self.draw) # cancel maneuver when finished if self.maneuver.finished: self.maneuver = None if self.RENDERING: self.draw.execute() return self.controls
def car_trajectory(self, car: Car, end_time: float, dt: float = 1 / 10): steps = [] test_car = Car(car) while test_car.time < end_time: dt = min(dt, end_time - test_car.time) test_car.step(Input(), dt) test_car.time += dt steps.append(vec3(test_car.position)) self.polyline(steps)
def update(self, game_car: PlayerInfo, packet: GameTickPacket): self.position = vector3_to_vec3(game_car.physics.location) self.velocity = vector3_to_vec3(game_car.physics.velocity) self.orientation = rotator_to_mat3(game_car.physics.rotation) self.angular_velocity = vector3_to_vec3(game_car.physics.angular_velocity) self.boost = game_car.boost self.time = packet.game_info.seconds_elapsed self.on_ground = game_car.has_wheel_contact # Reset ctrl every tick. self.controls = Input()
def __init__(self, car: Car, info: Game): self.target: vec3 = None self.car: Car = car self.info = info self.hover = Hover(car) self.drive = Drive(car) self.controls: Input = Input() self.__time_spent_on_ground = 0.0
def step(self, dt): if self.jumping: self.controls = Input() # first jump for full 0.2 sec if self.timer <= 0.2: self.controls.jump = True # single tick between jumps elif self.timer <= 0.2 + dt * JUMP_FALSE_TICKS: self.controls.jump = False # second jump else: self.controls.jump = True self.jumping = False self.timer += dt else: self.finished = self.intercept.time < self.info.time if self.car.on_ground: # manage speed before jump distance_to_target = ground_distance(self.car.position, self.intercept.position) if distance_to_target < MIN_DIST_BEFORE_SPEED_CONTROL: target_speed = distance_to_target / self.time_for_jump self.drive.target_speed = -target_speed if self._should_strike_backwards else target_speed self.drive.step(dt) self.controls = self.drive.controls else: super().step(dt) # decide when to jump ground_vel = ground(self.car.velocity) direction_to_target = ground_direction(self.car.position, self.intercept.position) alignment = dot(normalize(ground_vel), direction_to_target) # check alignment if alignment >= MIN_ALIGNMENT: # check that speed is correct speed_in_direction = dot(ground_vel, direction_to_target) time_to_target = distance_to_target / speed_in_direction if self.time_for_jump - ALLOWED_TIME_ERROR <= time_to_target <= self.time_for_jump + ALLOWED_TIME_ERROR: self.jumping = True # after jump (when the car is in the air) else: # face the ball for some additional height self.reorient.target_orientation = look_at( direction(self.car.position, self.info.ball), vec3(0, 0, 1)) self.reorient.step(dt) self.controls = self.reorient.controls
def __init__(self): a = Input() a.throttle = True b = Input() b.jump = True b.pitch = 1.0 movements = [ MovementInInterval(0.0, 3.0, a), MovementInInterval(3.0, 4.2, b) ] super().__init__(movements, clone_delay=0.8)
def __init__(self, car: Car, use_boost=False): self.car = car self.use_boost = use_boost self.controls = Input() self.dodge = Dodge(car) self.dodge.duration = 0.12 self.dodge.direction = vec2(car.forward() * (-1)) self.s = 0.95 * sgn( dot(self.car.angular_velocity, self.car.up()) + 0.01) self.timer = 0.0 self.finished = False
def __init__(self, car): self.car: Car = car self.controls: Input = Input() self.finished: bool = False
def set_controls(self, controls: Input): controls.boost = True
def __init__(self, car: Car, info: Game): self.car: Car = car self.info: Game = info self.controls = Input()
def set_controls(self, controls: Input): controls.throttle = 1
def set_controls(self, controls: Input): controls.pitch = 0.5 controls.boost = True
def __init__(self, car: Car): self.turn = AerialTurn(car) self.target: vec3 = None self.car: Car = car self.up: vec3 = None self.controls: Input = Input()
def __init__(self, car: Car, index: int): self.car = car self.index = index self.controls: Input = Input() self.maneuver: Optional[Maneuver] = None
def get_output(self, packet: GameTickPacket): self.time = packet.game_info.seconds_elapsed dt = self.time - self.prev_time if packet.game_info.is_kickoff_pause and not isinstance( self.maneuver, Kickoff): self.maneuver = None self.prev_time = self.time self.ticks += 1 self.info.read_packet(packet, self.get_field_info()) self.strategy.packet = packet if self.ticks < 10: return Input() #reset maneuver when another car hits the ball touch = packet.game_ball.latest_touch if ((touch.time_seconds > self.last_touch_time and touch.player_name != packet.game_cars[self.index].name) or (touch.player_name == '' and # if latest touch info is missing any([ distance(self.info.ball, car) < 300 for car in self.info.opponents + self.info.teammates ]))): self.last_touch_time = touch.time_seconds if (self.info.my_car.on_ground and not self.controls.jump and (not isinstance(self.maneuver, ShadowDefense) or self.maneuver.travel.driving)): self.maneuver = None #self.reset_time = self.time if self.handle_training_matchcomms(): self.info.predict_ball( self.PREDICTION_RATE * self.PREDITION_DURATION, 1 / self.PREDICTION_RATE) self.maneuver = get_maneuver_by_name(self.matchcomms_message, self.info) print("Training: Setting " + self.matchcomms_message) # choose maneuver if self.maneuver is None: if self.RENDERING: self.draw.clear() self.info.predict_ball( self.PREDICTION_RATE * self.PREDITION_DURATION, 1 / self.PREDICTION_RATE) self.maneuver = self.strategy.choose_maneuver() name = str(type(self.maneuver).__name__) print(name) self.last_ball_vel = norm(self.info.ball.velocity) # execute maneuver if self.maneuver is not None: self.maneuver.step(dt) self.controls = self.maneuver.controls if self.RENDERING: self.draw.group("maneuver") self.maneuver.render(self.draw) if self.maneuver.finished: self.maneuver = None for pad in self.info.large_boost_pads: self.draw.string(pad.position, str(pad.is_full_boost)) if self.RENDERING: self.draw.execute() self.maybe_chat(packet) self.chat.step(packet) return self.controls