Skip to content

Movement and stopping

Coordinates in tiles, an order that lasts ten seconds, and «stop» that does not mean «freeze»

tick 0
Unit Bind0
type
Unit Control1
typexy
Sensor2
=
in
Sensor3
=
in
@counter0number
xnullnull
ynullnull
ubind @poly
ucontrol move 16 4 0 0 0

Two lines, and the poly flies to tile 16 4. Watch x: it grows while the unit is on its way and settles around sixteen once it has arrived.

Field What is in it
first move
second and third the target’s coordinates in tiles
the rest unused by move, write zeroes

The coordinates are the same as @x and @y: map tiles, not world units. So “fly to the store” is sensor x container1 @x, sensor y container1 @y and those same numbers in move.

Control of a unit lasts ten seconds — 600 ticks. Every new order starts that count again, and when the time runs out the unit returns to its usual behaviour: a poly flies off to repair buildings, a dagger walks to the nearest enemy.

Movement simply stops at that point — there is nobody left to drive it. But the work it was given stays: mining, building and the flag survive the timer and are removed only by a new order.

So a program about units almost always looks like this: bind, command, end the iteration — and start again. There is nothing wasteful about it; a repeated order does not knock the unit off course.

tick 0
Unit Bind0
type
Sensor1
=
in
Jump -> 52
if
Unit Control3
typexy
End4
Unit Control5
type
@counter0number
xnullnull

Here the program leads the poly to 16 4, but as soon as x passes ten it issues ucontrol stop. The unit then coasts several more tiles, and x settles around seventeen — past the target.

stop means “I am no longer driving you”, not “stand still”. Speed is killed by drag, and a flying unit carries a long way.

Command What it does
move straight to a point, ignoring the terrain
approach towards a point, stopping at a given radius
pathfind to a point by road — a ground unit walks round a wall
autoPathfind where the unit would go by itself: to the enemy core
boost lift a ground unit into the air, if it can
idle do nothing, but stay under control

approach comes in handy when getting right up close is unnecessary: to a turret to repair it, or to an enemy at firing range. Its radius is in the third field, in tiles as well.

Unofficial fan project, not affiliated with Anuke. Mindustry sprites, fonts and translations © Anuke, used under GPL-3.0; Fira Code under OFL-1.1. Site code is GPL-3.0.