def step(self, packet: GameTickPacket) -> SimpleControllerState: local = self.agent.rotation_matrix.dot( self.agent.impact - Vector3(self.agent.car.physics.location)) steer_correction_radians = math.atan2(local.y, local.x) wrap_yaw = (self.allow_yaw_wrap and abs(steer_correction_radians) > math.pi * 0.75 and self.pitch and self.yaw) controller: SimpleControllerState = SimpleControllerState() if self.roll: controller.roll = clamp11(self.agent.car.physics.rotation.roll * -3 + self.agent.rotation_velocity.x * (10**10 if wrap_yaw else 0.3)) if abs(self.agent.car.physics.rotation.roll) < 1.5 or not self.roll: if self.pitch: controller.pitch = clamp11( (self.agent.car.physics.rotation.pitch - math.pi if wrap_yaw else self.agent.car.physics.rotation.pitch) * -4 + self.agent.rotation_velocity.y * 0.8) if self.yaw: yaw = (invert_angle(steer_correction_radians) if wrap_yaw else steer_correction_radians) controller.yaw = clamp11(yaw * 3.75 - self.agent.rotation_velocity.z * 0.95) controller.throttle = 0.03 # Don't turtle. controller.jump = False if not self.finished: self.finished = self.agent.car.has_wheel_contact return controller
def step(self, packet: GameTickPacket) -> SimpleControllerState: wrap_yaw = (self.allow_yaw_wrap and abs(self.agent.steer_correction_radians) > math.pi * 0.75 and self.pitch and self.yaw) controller: SimpleControllerState = SimpleControllerState() if self.roll: controller.roll = clamp11(self.agent.car.physics.rotation.roll * -3 + self.rotation_velocity.x * 0.3) if abs(self.agent.car.physics.rotation.roll) < 1.5 or not self.roll: if self.pitch: controller.pitch = clamp11((self.agent.car.physics.rotation.pitch - math.pi if wrap_yaw else self.agent.car.physics.rotation.pitch) * -4 + self.rotation_velocity.y * 0.8) if self.yaw: yaw = invert_angle(self.agent.steer_correction_radians) if wrap_yaw else self.agent.steer_correction_radians controller.yaw = clamp11(yaw * 3.75 - self.rotation_velocity.z * 0.95) return controller
def dodge(self, angle: float, rotation_velocity: Vector3, multiply = 1): self.controller.yaw = 0 if self.car.has_wheel_contact and not self.dodging: self.dodge_angle = angle self.dodging = True self.controller.jump = True self.controller.pitch = -sign(math.cos(self.dodge_angle)) self.next_dodge_time = self.time + 0.25 else: if self.time > self.next_dodge_time: self.controller.jump = True if self.car.has_wheel_contact or self.time > self.next_dodge_time + 1.5: self.dodging = False if self.time < self.next_dodge_time + 0.5: self.controller.roll = clamp11(math.sin(self.dodge_angle) * multiply) self.controller.pitch = clamp11(-math.cos(self.dodge_angle)) elif self.time < self.next_dodge_time + 1: self.controller.roll = 0 self.controller.pitch = 0 else: recover(self, rotation_velocity, yaw = (self.car.physics.location.z > 1000))
def recover( self, rotation_velocity: Vector3, roll=True, pitch=True, yaw=True, allow_yaw_wrap: bool = True, ): wrap_yaw = ( allow_yaw_wrap and abs(self.steer_correction_radians) > math.pi * 0.75 and pitch and yaw ) if roll: self.controller.roll = clamp11( self.car.physics.rotation.roll * -3 + rotation_velocity.x * 0.3 ) if abs(self.car.physics.rotation.roll) < 1.5 or not roll: if pitch: self.controller.pitch = clamp11( ( self.car.physics.rotation.pitch - math.pi if wrap_yaw else self.car.physics.rotation.pitch ) * -4 + rotation_velocity.y * 0.8 ) if yaw: self.controller.yaw = clamp11( ( invert_angle(self.steer_correction_radians) if wrap_yaw else self.steer_correction_radians ) * 3.75 - rotation_velocity.z * 0.95 )