# LinearTargeting/NanoLinearTargeting

Robo Home | LinearTargeting | Changes | Preferences | AllPages

Showing revision 1
This code gives decent LinearTargeting with a very small code size. However, the aim is slightly imprecise and it ignores walls. The basic code is used in a lot of NanoBots:

How It Works:

We first find the other robot's LateralVelocity (how fast the other robot is moving parallel to you) with

To find an approximate angle offset, you assume they'll continue moving parallel with you at their lateral velocity until your bullet reaches them, giving you a triangle like this:

/|
/a|
bullet speed * bullet travel time   /  |
/   |
/____|

lateral velocity * bullet travel time

So you're angle offset is

asin((lateral velocity * bullet travel time) / (bulletSpeed velocity * bulllet travel time)) = asin(lateral velocity / bullet speed)
It turns out that asin(lateral velocity / bullet speed) is almost exactly the same as (lateral velocity / bullet speed), so we get rid of the asin for some more code size. The above code uses 13.0 for bullet speed, but this actually results in aiming that works better for a slightly lower speed than 13 because of the distortion from removing asin.

Finally, we add the offset to the absolute bearing to get the firing angle, and subtract the gun heading to get the gun turn. -- Kev

Robo Home | LinearTargeting | Changes | Preferences | AllPages
Edit revision 1 of this page | View other revisions | View current revision
Edited October 21, 2006 21:09 EST by Kev (diff)
Search: