22
33from rlbot .agents .base_agent import BaseAgent , SimpleControllerState
44from rlbot .utils .structures .game_data_struct import GameTickPacket
5+ from rlbot .utils .structures .quick_chats import QuickChats
56
67from util .orientation import Orientation
8+ from util .spikes import SpikeWatcher
79from util .vec import Vec3
810from util .sequence import Sequence , ControlStep
911
@@ -14,17 +16,22 @@ def initialize_agent(self):
1416 # This runs once before the bot starts up
1517 self .controller_state = SimpleControllerState ()
1618 self .active_sequence : Sequence = None
19+ self .spike_watcher = SpikeWatcher ()
1720
1821 def get_output (self , packet : GameTickPacket ) -> SimpleControllerState :
1922
2023 if self .active_sequence and not self .active_sequence .done :
2124 return self .active_sequence .tick (packet )
2225
26+ self .spike_watcher .read_packet (packet )
27+
2328 ball_location = Vec3 (packet .game_ball .physics .location )
2429 my_car = packet .game_cars [self .index ]
2530 car_location = Vec3 (my_car .physics .location )
2631 car_velocity = Vec3 (my_car .physics .velocity )
2732
33+ # Example of using a sequence
34+ # This will do a front flip if the car's velocity is between 550 and 600
2835 if 550 < car_velocity .length () < 600 :
2936 self .active_sequence = Sequence ([
3037 ControlStep (0.05 , SimpleControllerState (jump = True )),
@@ -34,13 +41,23 @@ def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
3441 ])
3542 return self .active_sequence .tick (packet )
3643
37- car_to_ball = ball_location - car_location
44+ # Example of using the spike watcher.
45+ # This will make the bot say I got it! when it spikes the ball,
46+ # then release it 3 seconds later.
47+ if self .spike_watcher .carrying_car == my_car :
48+ if self .spike_watcher .carry_duration == 0 :
49+ self .send_quick_chat (QuickChats .CHAT_EVERYONE , QuickChats .Information_IGotIt )
50+ elif self .spike_watcher .carry_duration > 3 :
51+ return SimpleControllerState (use_item = True )
3852
53+ # The rest of this code just ball chases.
3954 # Find the direction of our car using the Orientation class
4055 car_orientation = Orientation (my_car .physics .rotation )
4156 car_direction = car_orientation .forward
4257
43- steer_correction_radians = find_correction (car_direction , car_to_ball )
58+ target = ball_location
59+ car_to_target = target - car_location
60+ steer_correction_radians = find_correction (car_direction , car_to_target )
4461
4562 self .controller_state .throttle = 1.0
4663 self .controller_state .steer = - 1 if steer_correction_radians > 0 else 1.0
0 commit comments