|
1 | 1 | import math |
2 | 2 |
|
3 | | -from rlbot.agents.base_flatbuffer_agent import BaseFlatbufferAgent, SimpleControllerState |
4 | | -from rlbot.messages.flat import GameTickPacket |
| 3 | +from rlbot.agents.base_agent import BaseAgent, SimpleControllerState |
| 4 | +from rlbot.utils.structures.game_data_struct import GameTickPacket |
5 | 5 |
|
6 | 6 | URotationToRadians = math.pi / float(32768) |
7 | 7 |
|
8 | 8 |
|
9 | | -class PythonExample(BaseFlatbufferAgent): |
| 9 | +class PythonExample(BaseAgent): |
10 | 10 |
|
11 | 11 | def get_output(self, packet: GameTickPacket) -> SimpleControllerState: |
12 | 12 | controller_state = SimpleControllerState() |
13 | 13 |
|
14 | | - if packet.Ball() is None: # This happens during replays |
15 | | - return controller_state |
| 14 | + ball_location = Vector2(packet.game_ball.physics.location.x, packet.game_ball.physics.location.y) |
16 | 15 |
|
17 | | - ball_location = Vector2(packet.Ball().Physics().Location().X(), packet.Ball().Physics().Location().Y()) |
18 | | - |
19 | | - my_car = packet.Players(self.index) |
20 | | - car_location = Vector2(my_car.Physics().Location().X(), my_car.Physics().Location().Y()) |
| 16 | + my_car = packet.game_cars[self.index] |
| 17 | + car_location = Vector2(my_car.physics.location.x, my_car.physics.location.y) |
21 | 18 | car_direction = get_car_facing_vector(my_car) |
22 | 19 | car_to_ball = ball_location - car_location |
23 | 20 |
|
@@ -64,8 +61,8 @@ def correction_to(self, ideal): |
64 | 61 |
|
65 | 62 |
|
66 | 63 | def get_car_facing_vector(car): |
67 | | - pitch = car.Physics().Rotation().Pitch() |
68 | | - yaw = car.Physics().Rotation().Yaw() |
| 64 | + pitch = float(car.physics.rotation.pitch) |
| 65 | + yaw = float(car.physics.rotation.yaw) |
69 | 66 |
|
70 | 67 | facing_x = math.cos(pitch) * math.cos(yaw) |
71 | 68 | facing_y = math.cos(pitch) * math.sin(yaw) |
|
0 commit comments