Colobot Wiki
Advertisement

With the instruction distance( , ) you can calculate the distance between two positions.

Basic use[]

If you write position alone, this gives you the position of the bot that executes the program. If you write the name of a variable followed by .position, this gives you the position of the object described in the variable.

Here is a program that moves forward, covering exactly the distance between the bot and the closest ant:

	item = radar(AlienAnt);
	move(distance(position, item.position));

This is of course pure suicide. Better to stop 40 meters before, in order to be at shooting range:

	item = radar(AlienAnt);
	move(distance(position, item.position) - 40);

For specialists[]

Syntax:

distance ( pos1, pos2 );

Calculates the distance between two positions. 

pos1, pos2: point[]

Coordinates of the two positions.  

Return value: float[]

Distance between the two positions.

See also[]

Advertisement