Skip to content

Arrival: within

A unit will never stand exactly on a point. The question to ask is not «is it there» but «is it close»

tick 0
Unit Bind0
type
Unit Control1
typexy
Unit Control2
typexyradiusresult
Sensor3
=
in
@counter0number
arrivednullnull
xnullnull
ucontrol move 16 4 0 0 0
ucontrol within 16 4 2 arrived 0

While the poly is flying, arrived is zero; once it comes within two tiles of the target, it becomes one. Note x: the unit settled around 15.87, not exactly on sixteen.

Field What is in it
first within
second and third a point in tiles
fourth the radius, also in tiles
fifth where to put the answer: 1 or 0

within does nothing to the unit: it only answers. So it does not take control — a unit nobody has commanded will not fall under control from a within alone. unbind behaves the same way.

But control that has already been taken is extended by within: if the unit was commanded earlier, every question refreshes the ten-second term just as an order does.

ucontrol move 16 4 0 0 0
ucontrol within 16 4 2 arrived 0
jump 0 equal arrived 0

Here move is repeated together with the check, and that is the right shape of waiting: the order keeps the unit on course rather than merely holding the term open.

Radius When
1–2 tiles ordinary “has arrived”
3–5 tiles switching to the next waypoint, where precision does not matter
transfer range before itemTake and itemDrop: the unit has to get right up close

Too small a radius and the unit is for ever “almost there”: inertia will not let it stop half a tile from the target. Too large, and the program decides it has arrived while the store is still a flight away.

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.