IBasicEvents OnHitRobot Method Robocode Robot API for .NET
This method is called when your robot collides with another robot. You should override it in your robot if you want to be informed of this event.

Examples

void OnHitRobot(HitRobotEvent evnt)
{
    if (event.Bearing > -90 && evnt.Bearing <= 90)
    {
        Back(100);
    }
    else
    {
        Ahead(100);
    }
}
public void OnHitRobot(HitRobotEvent evnt)
{
    if (event.Bearing > -90 && evnt.Bearing <= 90)
    {
        SetBack(100);
    }
    else
    {
        SetAhead(100);
    }
}
-- or perhaps, for a more advanced robot --

The angle is relative to your robot's facing. So 0 is straight ahead of you.

This event can be generated if another robot hits you, in which case IsMyFault will return false. In this case, you will not be automatically stopped by the game -- but if you continue moving toward the robot you will hit it (and generate another event). If you are moving away, then you won't hit it.

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

void OnHitRobot(
	HitRobotEvent evnt
)
See Also