thebotslam

How do I aim and fire my bot's laser?

Fire on what the scanner sees

from bot import Chassis, Scanner, Laser, wait

chassis = Chassis(0)
scanner = Scanner(1)
laser = Laser(2)

while True:
    if scanner.ping(0):
        b = scanner.bearing(0)
        scanner.sense = b      # keep the arc on it
        if laser.ready:
            laser.fire(b)      # the turret turns to b and fires
    else:
        scanner.sense = chassis.heading
    wait()

A bot that fires whenever it's ready fires every 10 ticks.

How a shot works

Don't hit your own side

Friendly fire is on. A teammate near where the beam stops is hit too, and so is your own bot if it fires at something it's touching. The beam also stops at the first thing in its way, so a teammate between you and the enemy takes the shot.

More than one laser

Two lasers on different channels each have their own cooldown:

if laser.ready:
    laser.fire(b)
elif laser2.ready:
    laser2.fire(b)

Here laser2 = Laser(3) connects the second one. Other weapons, such as rockets, mortars and missiles, aim and fire in their own ways; the Reference in Brain code covers each.