Skip to content

Commit f94c51b

Browse files
committed
Smooth steering, better spike threshold, documentation.
1 parent 935acd8 commit f94c51b

3 files changed

Lines changed: 39 additions & 6 deletions

File tree

rlbot.cfg

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,13 @@
66

77
[Match Configuration]
88
# Number of bots/players which will be spawned. We support up to max 64.
9-
num_participants = 2
9+
num_participants = 1
1010
game_mode = Soccer
1111
game_map = Mannfield
1212

1313
[Mutator Configuration]
1414
# Visit https://github.com/RLBot/RLBot/wiki/Config-File-Documentation to see what you can put here.
15+
Rumble = Spike Rush
1516

1617
[Participant Configuration]
1718
# Put the name of your bot config file here. Only num_participants config files will be read!

src/bot.py

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
8099
def 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

99120
def 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:

src/util/spikes.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22

33
from util.vec import Vec3
44

5+
# When the ball is attached to a car's spikes, the distance will vary a bit depending on whether the ball is
6+
# on the front bumper, the roof, etc. It tends to be most far away when the ball is on one of the front corners
7+
# and that distance is a little under 200. We want to be sure that it's never over 200, otherwise bots will
8+
# suffer from bad bugs when they don't think the ball is spiked to them but it actually is; they'll probably
9+
# drive in circles. The opposite problem, where they think it's spiked before it really is, is not so bad because
10+
# they usually spike it for real a split second later.
11+
MAX_DISTANCE_WHEN_SPIKED = 200
512

613
class SpikeWatcher:
714
def __init__(self):
@@ -17,7 +24,7 @@ def read_packet(self, packet: GameTickPacket):
1724
car = packet.game_cars[i]
1825
car_location = Vec3(car.physics.location)
1926
distance = car_location.dist(ball_location)
20-
if distance < 195:
27+
if distance < MAX_DISTANCE_WHEN_SPIKED:
2128
if distance < closest_distance:
2229
closest_candidate = car
2330
closest_distance = distance
@@ -27,4 +34,3 @@ def read_packet(self, packet: GameTickPacket):
2734
self.carrying_car = closest_candidate
2835
if self.carrying_car is not None:
2936
self.carry_duration = packet.game_info.seconds_elapsed - self.spike_moment
30-
print(closest_distance)

0 commit comments

Comments
 (0)