IBasicEvents OnScannedRobot Method Robocode Robot API for .NET
This method is called when your robot sees another robot, i.e. when the robot's radar scan "hits" another robot. You should override it in your robot if you want to be informed of this event. (Almost all robots should override this!)

This event is automatically called if there is a robot in range of your radar.

Note that the robot's radar can only see robot within the range defined by RADAR_SCAN_RADIUS (1200 pixels).

Also not that the bearing of the scanned robot is relative to your robot's heading.

Examples

void OnScannedRobot(ScannedRobotEvent evnt)
{
    // Assuming radar and gun are aligned... 
    if (event.Distance < 100)
    {
        Fire(3);
    }
    else
    {
        Fire(1);
    }
}

Note:
The game assists Robots in firing, as follows:
  • If the gun and radar are aligned (and were aligned last turn),
  • and the event is current,
  • and you call Fire() before taking any other actions, Robot.Fire(double) will Fire directly at the robot.

In essence, this means that if you can see a robot, and it doesn't move, then Fire will hit it.

AdvancedRobots will NOT be assisted in this manner, and are expected to examine the event to determine if Fire(Double) would hit. (i.e. you are spinning your gun around, but by the time you get the event, your gun is 5 degrees past the robot).

Namespace: Robocode.RobotInterfaces
Assembly: robocode (in robocode.dll) Version: 1.9.3.0
Syntax

void OnScannedRobot(
	ScannedRobotEvent evnt
)
See Also