-
Notifications
You must be signed in to change notification settings - Fork 5
/
rocketsimvis_rlgym_sim_client.py
49 lines (34 loc) · 1.08 KB
/
rocketsimvis_rlgym_sim_client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import socket
import json
from rlgym_sim.utils.gamestates import GameState
UDP_IP = "127.0.0.1"
UDP_PORT = 9273 # Default RocketSimVis port
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) # UDP
def write_physobj(physobj):
j = {}
j['pos'] = physobj.position.tolist()
j['forward'] = physobj.forward().tolist()
j['up'] = physobj.up().tolist()
j['vel'] = physobj.linear_velocity.tolist()
j['ang_vel'] = physobj.angular_velocity.tolist()
return j
def write_car(player):
j = {}
j['team_num'] = int(player.team_num)
j['phys'] = write_physobj(player.car_data)
j['boost_amount'] = player.boost_amount * 100
j['on_ground'] = bool(player.on_ground)
j['is_demoed'] = bool(player.is_demoed)
j['has_flip'] = bool(player.has_flip)
return j
def send_state_to_rocketsimvis(gs: GameState):
j = {}
# Send ball
j['ball_phys'] = write_physobj(gs.ball)
# Send cars
j['cars'] = []
for player in gs.players:
j['cars'].append(write_car(player))
# Send boost pad states
j['boost_pad_states'] = gs.boost_pads.tolist()
sock.sendto(json.dumps(j).encode('utf-8'), (UDP_IP, UDP_PORT))