I couldn't get it to work, can you try it on the pic I posted above and walk me through it plz. I'm not very familiar with vector math, mostly trig =P
Edited by - kingpin on October 22, 2001 12:29:38 AM
AI missle trajectory prediction.
I took a break and took another crack at the problem (Thanx Oluseyi).
Point E'' at any time t can be defined as:
E''(x,y) = (cos(e)(Ev)(t) + Ex, sin(e)(Ev)(t) + Ey)
dx = ABS(Ex - Bx)
dy = ABS(Ey - By)
The difference in velocity between BT and ET is:
dv = Bv/Ev
So the length between ET and BT should be equal at time t which is:
(t)(dv) = sqrt( (E''x - Bx)^2 + (E''y - By)^2 )
(t*dv)^2 = (cos(e)(Ev)(t) + dx)^2 + (sin(e)(Ev)(t) + dy)^2
(t*dv)^2 = (cos(e)(Ev)(t))^2 + 2(dx)cos(e)(Ev)(t) + dx^2 +
(sin(e)(Ev)(t))^2 + 2(dy)sin(e)(Ev)(t) + dy^2
dv^2 - dx^2 - dy^2 = (cos(e)(Ev))^2 + (sin(e)(Ev))^2 +
(1/t) * (2(dx)cos(e)(Ev) + 2(dy)sin(e)(Ev))
...
Then it boils down to a quadratic formula:
((t^2)(dv^2 - (cos(e)(Ev))^2 - (sin(e)(Ev))^2)) / (dx^2 + dy^2) -
((2)(t)((dx)cos(e)(Ev) + (dy)sin(e)(Ev))) / (dx^2 + dy^2) - 1 = 0
Using the quadratic equation:
a = (dv^2 - (cos(e)(Ev))^2 - (sin(e)(Ev))^2)) / (dx^2 + dy^2)
b = ((2)((dx)cos(e)(Ev) + (dy)sin(e)(Ev))) / (dx^2 + dy^2)
t = (b +- sqrt( b^2 + 4a )) / (2a)
T(x,y) = (cos(e)(Ev)(t) + Ex, sin(e)(Ev)(t) + Ey)
BT = sqrt( (Tx - Bx)^2 + (Ty - By)^2 )
Angle b = 1 / cos(Tx / BT)
If you find any errors, plz let me know.
Point E'' at any time t can be defined as:
E''(x,y) = (cos(e)(Ev)(t) + Ex, sin(e)(Ev)(t) + Ey)
dx = ABS(Ex - Bx)
dy = ABS(Ey - By)
The difference in velocity between BT and ET is:
dv = Bv/Ev
So the length between ET and BT should be equal at time t which is:
(t)(dv) = sqrt( (E''x - Bx)^2 + (E''y - By)^2 )
(t*dv)^2 = (cos(e)(Ev)(t) + dx)^2 + (sin(e)(Ev)(t) + dy)^2
(t*dv)^2 = (cos(e)(Ev)(t))^2 + 2(dx)cos(e)(Ev)(t) + dx^2 +
(sin(e)(Ev)(t))^2 + 2(dy)sin(e)(Ev)(t) + dy^2
dv^2 - dx^2 - dy^2 = (cos(e)(Ev))^2 + (sin(e)(Ev))^2 +
(1/t) * (2(dx)cos(e)(Ev) + 2(dy)sin(e)(Ev))
...
Then it boils down to a quadratic formula:
((t^2)(dv^2 - (cos(e)(Ev))^2 - (sin(e)(Ev))^2)) / (dx^2 + dy^2) -
((2)(t)((dx)cos(e)(Ev) + (dy)sin(e)(Ev))) / (dx^2 + dy^2) - 1 = 0
Using the quadratic equation:
a = (dv^2 - (cos(e)(Ev))^2 - (sin(e)(Ev))^2)) / (dx^2 + dy^2)
b = ((2)((dx)cos(e)(Ev) + (dy)sin(e)(Ev))) / (dx^2 + dy^2)
t = (b +- sqrt( b^2 + 4a )) / (2a)
T(x,y) = (cos(e)(Ev)(t) + Ex, sin(e)(Ev)(t) + Ey)
BT = sqrt( (Tx - Bx)^2 + (Ty - By)^2 )
Angle b = 1 / cos(Tx / BT)
If you find any errors, plz let me know.
Someone said that sometimes there may be no solution, well also sometimes there may be more than 1 solution. For example, the bot could shoot just ahead of a near-by target, or he could shoot a longer way ahead of the target, but since the bullet would take longer to get there, it would still hit. If there is more than 1 solution, you may want to choose the quickest one, so that the human player doesn''t get as much time to react and avoid the shot.
Oh, I know for sure there''s more than one solution, and there''s hundreds of versions of this problem too. I remember there was a post about a day after I started this post dealing with a similiar problem, but just a bit different. And it required a completely different algorithm. This tracking algorithm isn''t that ''smart'' either, just as you mentioned, if the enemy doesn''t move at a constant velocity and direction. Say the enemy jukes left or stops completely after the missle is launched, the missle will probably miss.
I''m actually using this for robocode where the bullet velocity is constant, and max enemy velocity is always below the bullet velocity (robocode is a 2D overhead tank battle, where you can create custom bots IN JAVA)!
...
I''m sure there''s no one algorithm for something as complex as say, tracking a football running back with a missle of equal to or slightly greater than the velocity as the running back. My best guess would be to use neural networks and genetic algorithms. But instead of goin through all that trouble, you could just put the algorithm ''in'' the missle instead (which i can''t do in robocode), and perform the algorithm at timed intervals, it''d be just like a heat seeking missle.
"1-2GB of virtual memory, that''s way more than i''ll ever need!" - Bill Gates
I''m actually using this for robocode where the bullet velocity is constant, and max enemy velocity is always below the bullet velocity (robocode is a 2D overhead tank battle, where you can create custom bots IN JAVA)!
...
I''m sure there''s no one algorithm for something as complex as say, tracking a football running back with a missle of equal to or slightly greater than the velocity as the running back. My best guess would be to use neural networks and genetic algorithms. But instead of goin through all that trouble, you could just put the algorithm ''in'' the missle instead (which i can''t do in robocode), and perform the algorithm at timed intervals, it''d be just like a heat seeking missle.
"1-2GB of virtual memory, that''s way more than i''ll ever need!" - Bill Gates
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement