Skip to content

Shooting

A turret shoots well enough on its own. Logic is for when it matters who exactly it shoots

Without logic a turret picks its target itself: the nearest one in range. Logic steps in when that choice will not do — when one enemy has to be finished off instead of spreading fire, or when the more dangerous one has to be hit.

tick 0
Control0
set of
xy
shoot
Sensor1
=
in
Sensor2
=
in
Sensor3
=
in
@counter0number
shootingnullnull
ammonullnull
facingnullnull

Press “run”. The duo turns east and starts firing at the point 13 4, where a dagger stands: ammo goes down, and so does the dagger’s health.

Field What is in it
first the turret
second and third a point in map tiles, not in world units
fourth shoot or only aim: zero means turn silently

The coordinates are the same as any block’s @x and @y, so aiming at a building is just taking its coordinates and handing them to the turret.

A turret obeys logic for 120 ticks after the last command, then returns to its own aim and starts choosing targets by itself again.

tick 0
Radar0
target1target2target3sortradarsortOrderoutput
Control1
set of
unitshoot
Sensor2
=
in
Sensor3
=
in
@counter0number
aimnullnull
shootingnullnull
ammonullnull

Here the target is found by a radar, and shootp aims the turret with lead: it fires not where the unit is now but where it will be when the bullet arrives.

radar enemy any any distance duo1 1 aim
control shootp duo1 aim 1
Field What is in it
first the turret
second a unit, not coordinates
third shoot or only aim

The lead is worked out by the game, from the target’s speed and the bullet’s. So a duo leads a flying flare and puts its shot straight into a standing dagger.

Property What it gives
@shooting whether it is firing right now
@ammo how many units of ammunition are left
@ammoCapacity how many fit
@currentAmmoType the item it is loaded with: @copper, @graphite
@progress how ready the next shot is, from 0 to 1
@rotation where the barrel points
@shootX, @shootY where it is aiming

Ammo is counted not in items but in units of ammunition: one lump of copper gives two, graphite four. So a full duo’s @ammo is 30 while it holds fifteen items of copper.

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.