Skip to content

Commit 2eec834

Browse files
committed
Update rlgym_compat
1 parent 29b532a commit 2eec834

File tree

3 files changed

+26
-29
lines changed

3 files changed

+26
-29
lines changed

tests/necto/rlgym_compat/game_state.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
from typing import List
2-
31
import numpy as np
42

53
from rlbot import flat
@@ -11,12 +9,13 @@
119
class GameState:
1210
blue_score: int = 0
1311
orange_score: int = 0
14-
players: List[PlayerData] = []
12+
players: list[PlayerData] = []
1513
ball = PhysicsObject()
1614
inverted_ball = PhysicsObject()
1715

1816
_on_ground_ticks = np.zeros(64, dtype=np.float32)
19-
_air_time = np.zeros(64, dtype=np.float32)
17+
_air_time_since_jump = np.zeros(64, dtype=np.float32)
18+
_has_jumped: list[bool] = [False] * 64
2019

2120
def __init__(self, game_info: flat.FieldInfo):
2221
# List of "booleans" (1 or 0)
@@ -57,19 +56,21 @@ def _decode_player(
5756

5857
if player_info.air_state == flat.AirState.OnGround:
5958
self._on_ground_ticks[index] = 0
60-
self._air_time[index] = 0
59+
self._air_time_since_jump[index] = 0
60+
self._has_jumped[index] = False
6161
else:
6262
self._on_ground_ticks[index] += ticks_elapsed
6363

6464
if player_info.air_state == flat.AirState.Jumping:
65-
self._air_time[index] = 0
65+
self._air_time_since_jump[index] = 0
66+
self._has_jumped[index] = True
6667
elif player_info.air_state in {
6768
flat.AirState.DoubleJumping,
6869
flat.AirState.Dodging,
6970
}:
70-
self._air_time[index] = 150
71+
self._air_time_since_jump[index] = 150
7172
else:
72-
self._air_time[index] += ticks_elapsed
73+
self._air_time_since_jump[index] += ticks_elapsed
7374

7475
player_data.car_id = index
7576
player_data.team_num = player_info.team
@@ -79,9 +80,9 @@ def _decode_player(
7980
or self._on_ground_ticks[index] <= 6
8081
)
8182
player_data.ball_touched = False
82-
player_data.has_jump = player_info.air_state == flat.AirState.OnGround
83+
player_data.has_jump = not self._has_jumped[index]
8384
# RLGym does consider the timer/unlimited flip, but i'm to lazy to track that in rlbot
84-
player_data.has_flip = self._air_time[index] < 150
85+
player_data.has_flip = self._air_time_since_jump[index] < 150
8586
player_data.boost_amount = player_info.boost / 100
8687

8788
return player_data

tests/necto/rlgym_compat/physics_object.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@
66

77

88
class PhysicsObject:
9+
_has_computed_rot_mtx = False
10+
_rotation_mtx: np.ndarray = np.zeros((3, 3))
11+
_invert_vec: np.ndarray = np.asarray([-1, -1, 1])
12+
_invert_pyr: np.ndarray = np.asarray([0, math.pi, 0])
13+
914
def __init__(
1015
self,
1116
position=None,
@@ -15,21 +20,13 @@ def __init__(
1520
):
1621
self.position: np.ndarray = position if position else np.zeros(3)
1722

18-
# ones by default to prevent mathematical errors when converting quat to rot matrix on empty physics state
19-
self.quaternion: np.ndarray = np.ones(4)
20-
2123
self.linear_velocity: np.ndarray = (
2224
linear_velocity if linear_velocity else np.zeros(3)
2325
)
2426
self.angular_velocity: np.ndarray = (
2527
angular_velocity if angular_velocity else np.zeros(3)
2628
)
2729
self._euler_angles: np.ndarray = euler_angles if euler_angles else np.zeros(3)
28-
self._rotation_mtx: np.ndarray = np.zeros((3, 3))
29-
self._has_computed_rot_mtx = False
30-
31-
self._invert_vec = np.asarray([-1, -1, 1])
32-
self._invert_pyr = np.asarray([0, math.pi, 0])
3330

3431
def decode_car_data(self, car_data: flat.Physics):
3532
self.position = self._vector_to_numpy(car_data.location)

tests/necto/rlgym_compat/player_data.py

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,13 @@
22

33

44
class PlayerData(object):
5-
def __init__(self):
6-
self.car_id: int = -1
7-
self.team_num: int = -1
8-
self.is_demoed: bool = False
9-
self.on_ground: bool = False
10-
self.ball_touched: bool = False
11-
self.has_jump: bool = False
12-
self.has_flip: bool = False
13-
self.boost_amount: float = -1
14-
self.car_data: PhysicsObject = PhysicsObject()
15-
self.inverted_car_data: PhysicsObject = PhysicsObject()
5+
car_id: int = -1
6+
team_num: int = -1
7+
is_demoed: bool = False
8+
on_ground: bool = False
9+
ball_touched: bool = False
10+
has_jump: bool = False
11+
has_flip: bool = False
12+
boost_amount: float = -1
13+
car_data: PhysicsObject = PhysicsObject()
14+
inverted_car_data: PhysicsObject = PhysicsObject()

0 commit comments

Comments
 (0)