33from rlbot .utils .structures .game_data_struct import GameTickPacket
44
55from util .ball_prediction_analysis import find_slice_at_time
6+ from util .boost_pad_tracker import BoostPadTracker
67from util .drive import steer_toward_target
78from util .sequence import Sequence , ControlStep
89from util .vec import Vec3
@@ -13,38 +14,47 @@ class MyBot(BaseAgent):
1314 def __init__ (self , name , team , index ):
1415 super ().__init__ (name , team , index )
1516 self .active_sequence : Sequence = None
17+ self .boost_pad_tracker = BoostPadTracker ()
18+
19+ def initialize_agent (self ):
20+ # Set up information about the boost pads now that the game is active and the info is available
21+ self .boost_pad_tracker .initialize_boosts (self .get_field_info ())
1622
1723 def get_output (self , packet : GameTickPacket ) -> SimpleControllerState :
1824 """
1925 This function will be called by the framework many times per second. This is where you can
2026 see the motion of the ball, etc. and return controls to drive your car.
2127 """
2228
23- # Start the renderer. Make sure you call end_rendering at the end of this function.
24- self .renderer . begin_rendering ( )
29+ # Keep our boost pad info updated with which pads are currently active
30+ self .boost_pad_tracker . update_boost_status ( packet )
2531
2632 # This is good to keep at the beginning of get_output. It will allow you to continue
2733 # any sequences that you may have started during a previous call to get_output.
2834 if self .active_sequence and not self .active_sequence .done :
29- return self .active_sequence .tick (packet )
35+ controls = self .active_sequence .tick (packet )
36+ if controls is not None :
37+ return controls
3038
3139 # Gather some information about our car and the ball
3240 my_car = packet .game_cars [self .index ]
3341 car_location = Vec3 (my_car .physics .location )
3442 car_velocity = Vec3 (my_car .physics .velocity )
3543 ball_location = Vec3 (packet .game_ball .physics .location )
3644
37- if car_location .dist (ball_location ) > 1000 :
45+ if car_location .dist (ball_location ) > 1500 :
3846 # We're far away from the ball, let's try to lead it a little bit
3947 ball_prediction = self .get_ball_prediction_struct () # This can predict bounces, etc
4048 ball_in_future = find_slice_at_time (ball_prediction , packet .game_info .seconds_elapsed + 2 )
4149 target_location = Vec3 (ball_in_future .physics .location )
50+ self .renderer .draw_line_3d (ball_location , target_location , self .renderer .cyan ())
4251 else :
4352 target_location = ball_location
4453
4554 # Draw some things to help understand what the bot is thinking
4655 self .renderer .draw_line_3d (car_location , target_location , self .renderer .white ())
4756 self .renderer .draw_string_3d (car_location , 1 , 1 , f'Speed: { car_velocity .length ():.1f} ' , self .renderer .white ())
57+ self .renderer .draw_rect_3d (target_location , 8 , 8 , True , self .renderer .cyan (), centered = True )
4858
4959 if 750 < car_velocity .length () < 800 :
5060 # We'll do a front flip if the car is moving at a certain speed.
@@ -55,8 +65,6 @@ def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
5565 controls .throttle = 1.0
5666 # You can set more controls if you want, like controls.boost.
5767
58- # Send any drawing we may have done
59- self .renderer .end_rendering ()
6068 return controls
6169
6270 def begin_front_flip (self , packet ):
0 commit comments