def __init__(self, car: Car, ball_predictions, predicate: callable = None): self.ball: Ball = None self.is_viable = True #find the first reachable ball slice that also meets the predicate test_car = Car(car) test_aerial = Aerial(car) for ball in ball_predictions: test_aerial.target = ball.position test_aerial.arrival_time = ball.time # fake our car state :D dir_to_target = ground_direction(test_car.position, test_aerial.target) test_car.velocity = dir_to_target * max(norm(test_car.velocity), 1200) test_car.orientation = look_at(dir_to_target, vec3(0,0,1)) if test_aerial.is_viable() and (predicate is None or predicate(car, ball)): self.ball = ball break #if no slice is found, use the last one if self.ball is None: self.ball = ball_predictions[-1] self.is_viable = False self.time = self.ball.time self.ground_pos = ground(self.ball.position) self.position = self.ball.position
from rlutilities.linear_algebra import vec3, vec2, mat3, mat2 from rlutilities.mechanics import Dodge from rlutilities.simulation import Car c = Car() c.time = 0.0 c.position = vec3(1509.38, -686.19, 17.01) c.velocity = vec3(-183.501, 1398., 8.321) c.angular_velocity = vec3(0, 0, 0) c.orientation = mat3(-0.130158, -0.991493, -0.00117062, 0.991447, -0.130163, 0.00948812, -0.00955977, 0.0000743404, 0.999954) c.on_ground = True c.jumped = False c.double_jumped = False c.jump_timer = -1.0 c.dodge_timer = -1.0 dodge = Dodge(c) dodge.direction = vec2(-230.03, 463.42) dodge.jump_duration = 0.1333 dodge.delay = 0.35 f = open("dodge_simulation.csv", "w") for i in range(300): dodge.step(0.008333) print(c.time, dodge.controls.jump, dodge.controls.pitch, dodge.controls.yaw) c.step(dodge.controls, 0.008333) f.write(f"{c.time}, {c.position[0]}, {c.position[1]}, {c.position[2]}, "