@@ -22,6 +22,10 @@ def initialize_agent(self):
2222 self .spike_watcher = SpikeWatcher ()
2323
2424 def get_output (self , packet : GameTickPacket ) -> SimpleControllerState :
25+ """
26+ This function will be called by the framework many times per second. This is where you can
27+ see the motion of the ball, etc. and return controls to drive your car.
28+ """
2529
2630 if self .active_sequence and not self .active_sequence .done :
2731 return self .active_sequence .tick (packet )
@@ -61,7 +65,7 @@ def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
6165 return SimpleControllerState (use_item = True )
6266
6367 # The rest of this code just ball chases.
64- # Find the direction of our car using the Orientation class
68+ # Find the direction of your car using the Orientation class
6569 car_orientation = Orientation (my_car .physics .rotation )
6670 car_direction = car_orientation .forward
6771
@@ -70,15 +74,32 @@ def get_output(self, packet: GameTickPacket) -> SimpleControllerState:
7074 steer_correction_radians = find_correction (car_direction , car_to_target )
7175
7276 self .controller_state .throttle = 1.0
73- self .controller_state .steer = - 1 if steer_correction_radians > 0 else 1.0
77+
78+ # Change the multiplier to influence the sharpness of steering. You'll wiggle if it's too high.
79+ self .controller_state .steer = limit_to_safe_range (- steer_correction_radians * 5 )
7480
7581 draw_debug (self .renderer , [goal_text ])
7682
7783 return self .controller_state
7884
7985
86+ def limit_to_safe_range (value : float ) -> float :
87+ """
88+ Controls like throttle, steer, pitch, yaw, and roll need to be in the range of -1 to 1.
89+ This will ensure your number is in that range. Something like 0.45 will stay as it is,
90+ but a value of -5.6 would be changed to -1.
91+ """
92+ if value < - 1 :
93+ return - 1
94+ if value > 1 :
95+ return 1
96+ return value
97+
98+
8099def find_correction (current : Vec3 , ideal : Vec3 ) -> float :
81- # Finds the angle from current to ideal vector in the xy-plane. Angle will be between -pi and +pi.
100+ """
101+ Finds the angle from current to ideal vector in the xy-plane. Angle will be between -pi and +pi.
102+ """
82103
83104 # The in-game axes are left handed, so use -x
84105 current_in_radians = math .atan2 (current .y , - current .x )
@@ -97,6 +118,11 @@ def find_correction(current: Vec3, ideal: Vec3) -> float:
97118
98119
99120def draw_debug (renderer , text_lines : List [str ]):
121+ """
122+ This will draw the lines of text in the upper left corner.
123+ This function will automatically put appropriate spacing between each line
124+ so they don't overlap.
125+ """
100126 renderer .begin_rendering ()
101127 y = 250
102128 for line in text_lines :
0 commit comments