Psychic missile, seeking object

Hey everyone, I'm trying to make a missile of sorts to detect where an object is going and then itself move to that position. You know like some pixels in front of that object.
Basically i have a ball moving randomly on screen and that is the object my missile is to detect.
I managed to make a homing missile that always tries to go to the objects current position, but I'm not really sure how to make it psychic. I am thinking of something like taking the objects last three positions and create a vector to see where it is going.
Not sure though, anything to push me in the right direction is appreciated.

I am using Code::Blocks and openFrameworks, if that helps you to help me.
Thanks...
The simplest way is to simply extrapolate the last few points, however if you want something really smart, check out the Kalman filter. This filter will take a noisy input and make future predictions based on the observed trends.

The math is fairly intense (there have been a few dissertations written on these), and it can sometimes be hard to meet real-time due to the processing power required. If you do get it, it'll be awesome.

Edit: A quick search yeilds open source libraries that you can implement:
http://kalman.sourceforge.net/index.php
Last edited on
The extrapolation sounds right. I tried googling a formula for it, and i might just be really bad at the internet, but i could't find anything except for on wikipedia. And that one didn't make much sense to me.
Can you in some way explain it, either in code or just the formula?
If your ball is truely random, it can't be predicted. If it has a general destination, then you can do some behind the scenes work (the person sees something random, the computer knows it's a straight line with some deviation).

Anyway, I did something like this in a space game. Just think about one space ship trying to intercept another.

Basically, the ship to intercept has velocity and direction. The position of the ship is dependant upon time. Where will this ship be in a few moments? How far away is that from the intercepter, and what is the intercepter's max velocity? Can the interceptor get there?

There are the times when it is impossible to hit the other ship (it might be much faster), so you'll need to take care of that.

If the ball changes directions, perhaps it should tell the missle to change direction too (just a game right? probably less reasource hogging than the missle making sure it's going the right way all of the time).
Last edited on
This would effectively simulate a 1st order differential equation. It'd get more complicated as you add higher orders.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
mag ( X, Y )
{
  return sqrt(X*X + Y*Y)
}

cosLaw (X1, Y1, X2, Y2, X3, Y3)
{
   a = mag(X1-X2, Y1-Y2)
   b = mag(X2-X3, Y2-Y3)
   c = mag(X1-X3, Y1-Y3)
   return acos((a*a + b*b - c*c)/(2*a*b))
}


dMag = mag(Xn - Xn-1,Yn - Yn-1)
dAngle = cosLaw(Xn-2, Yn-2, Xn-1, Yn-1, Xn, Yn)

Xn+1 = Xn + dMag * cos(dAngle)
Yn+1 = Yn + dMag * sin(dAngle)



Last edited on
Thanks guys.
Not sure i can get it to work, but at least i know where to go.
Topic archived. No new replies allowed.