DarwinBotsManual
Open the app EspañolES

angle

Gives the angle from the bot to a point x y, in the same units as .aim: ready to store in .setaim.

Facts

Word
angle
Family
Advanced
Integer stack
pops 2, pushes 1
What it does
Pops a point (x below, y on top) and pushes the angle from the bot to it, in .aim units (0 to about 1256).
Cost
Advanced command; debugint and debugbool are free
Runs
inside a gene: in the condition (cond) and in the body (start or else)

x y angle pops a point (the x first, the y on top) and pushes the angle you have to look at to go from the bot to that point. The result is in the units of .aim: from 0 to about 1256, with 0 pointing right, 314 up, 628 left and 942 down.

The coordinates are the same ones that .xpos, .ypos, .refxpos and .refypos give, so the typical use is to aim at whatever is being seen and store the result in .setaim. That is what 4-d Swarmer, from the Bestiary, does in its gene for turning toward the vegetables; simplified, it looks like this:

cond
  *.eye5 0 >
start
  *.refxpos *.refypos angle .setaim store
  10 .up store
stop

It also works with a fixed point: 3000 2500 angle .setaim store aims toward (3000, 2500) from wherever the bot is.

Note that the angle is computed from the bot's current position, but reads such as *.refxpos arrive one cycle late; if the other bot moves fast, you aim at where it was. To know how much is left to turn from the current heading, combine it with anglecmp; for the distance to the same point, dist.