1. T-Shirt Tragic
    Devshed Novice (500 - 999 posts)

    Join Date
    Mar 2001
    Melbourne, Australia
    Rep Power

    moving target algorithm needed.

    Hi all,
    I've started to play a game called Robocode.
    It's a java game where you get to program your robot's AI to attack and avoid being attacked. ...
    trouble is whenever I lock on to a target and fire, the target has moved on by the time my bullet gets to its location.

    I know the target's initial location, its direction and speed.. the target's acceleration is 0.

    I know my location, and the speed of my bullet... the bullet velocity is constant.

    What I need to know is the approximate location of the target if it continues its course.

    The closest thing I could find was a moving target equation for quake robots which involved three dimensional space, accelleration and quadratic equations .. (my math sucks).

    any ideas?
  2. #2
  3. Big Endian
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    May 2001
    Fly-over country
    Rep Power
    Go to the following link and download some of the robots and look at their source code. Squigbot v2.8 just won 6 out of 6 on my machine. You might want to take a look at its targeting.

  4. #3
  5. No Profile Picture
    Canta como rafaé
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2001
    Rep Power
    As you say, one solution is to calculate the function that describes the last movements of the player and then guess its next position.

    This function can be calculated, AFAIK, with interpolation functions like polynomials and splines. Depending of the number of points you want to sample, the function degree rises (with 4 points, it's a polynomial of degree 3, a cubic one).

    With this function you can predict the next value (it would be more or less accurate depending on the separation with the last point).

    You can see an active example at


    The problem here is how to make it useful for 3D, because in the applet you'll see that you cannot turn. Maybe it involves having an interpolation function for each axis.

    I suggest you try to make this set of functions depending on time, not on pairs of axis.

    pos_X (t) = prediction interpolation function in time t
    pos_Y (t) = prediction interpolation function in time t
    pos_Z (t) = prediction interpolation function in time t

    Hope it helps

    'Y se ahogaron los dooos
    No eran duros pa pagar, cuñaaoo !!'
    El vagamundo - El risitas y su cuñao
  6. #4
  7. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Sao Paulo - SP - BRAZIL
    Rep Power

    There's a simple equation that will do the trick.

    Since the aceleration is 0, and it's the second time derivative of space you have this dif. eq:

    ------ == 0

    The solution is :

    S = S0 + V0 * t

    This solution is also valid for multidimensional spaces. So, if I understood the problem right your solution would be :

    Sx = S0x + V0x * t
    Sy = S0y + V0y * t

    where S0x is the initial position of the target projected on the x axis. V0x is its speed on the x axis and t is the time.

    If you have your speed &/| position on polar form (a magnitude and an angle) you can convert to the cartesian form (the one with the x and y axis) using this expression :

    x = M sin A
    y = M cos A

    Where M is the magnitude and A is the angle. X and Y are the cordinates on the cartesian form.

    To convert back to polar form
    M = sqrt ( x^2 + y^2)
    A = arctg (y/x)

    I hope this helps you.

    Sorry for the poor english... It's not my primary language... I must have mixed up at least one mathematical term here (they tend to differ a lot between diferent languages), but I hope someone can spot it and correct if it's wrong.

    Comments on this post

    • JimmyGosling agrees
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Sydney, NSW, Australia
    Rep Power
    You got the mathematical terms correct from what I read.
    Michael Bray

IMN logo majestic logo threadwatch logo seochat tools logo