def project_to_wall(point: Vector2, direction: Vector2) -> Vector2: wall = Vector2(sign(direction.x) * 4096, sign(direction.y) * 5120) dir_normal = direction.normalized x_difference = (abs( (wall.x - point.x) / dir_normal.x) if dir_normal.x != 0 else 10000) y_difference = (abs( (wall.y - point.y) / dir_normal.y) if dir_normal.y != 0 else 10000) if x_difference < y_difference: # Side wall is closer return Vector2(wall.x, point.y + dir_normal.y * x_difference) else: # Back wall is closer return Vector2(point.x + dir_normal.x * y_difference, wall.y)
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 invert_angle(angle: float) -> float: if angle != 0: return -(angle - sign(angle) * math.pi) return math.pi