• Advertisement


This topic is now archived and is closed to further replies.

AI missle trajectory prediction.

This topic is 5982 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I have a problem that i've been working on for the past few days. It's a tracking algorithm for my AI, my AI is supposed to predict what the projected position of the enemy is and based on the known max velocity of it's weapon, fire at a specific angle to intercept the enemy. The problem seems simple. A is the enemy, V is the bot, B is the projected position where V and A will meet.
     |a  /
     |  /
Given: A, V, Vv (velocity), Av (velocity), and Angle a. Find: B and Angle v. Where B is the location A and V will meet at time t. Rules: Angle a can be any angle. A and V can be at any location on the cartesian coords. I haven't had calculus yet, that's next year in college. (I seriously been workin on this for over 8 hours...no joke). Thx for any help. Edited by - kingpin on October 20, 2001 1:02:22 PM

Share this post

Link to post
Share on other sites
If i have grasped right you have a with a certain speed ( uniform , i assume that ) and b is the final point, then you have v with a certani speed , you want the angle a,don''t you?
well we can define the problem in function of time ( t ) parameter

so i have found ( sorry but i''m not good at ascci charts )
that cos(a)=(vx-ax)/(vx-ax-vspeed*t) , where t is time

if its not clear or i have misunderstood please , tell me

Share this post

Link to post
Share on other sites
Not really. (I really wish I could post a pic up here.)

Lemme explain the problem in lazy mans terms...

Picture youself holding a gun and you know your position.
You can see your enemy, you know his position and velocity, you just need to determine what angle to aim the gun to intercept him. You can do this because you know the velocity the bullet travels. I really cant draw a clearer pic in ASCii, sorry.

In the pic above, the point V represents you, A represents the enemy, the lowercase a,v are angles. B is the point where your bullet will hit the enemy.

I could make this bright as white if I could post a pic.

Share this post

Link to post
Share on other sites
I''ve been puzzling over this, and, even though it sounds like it should be simple, I''m confused as hell.

There are a couple of things you''ll have to take into account:

There is not always a solution. If the target moves faster than the projectile, there are many configurations in which you won''t be able to hit it. I think I figured out a way to determine if the target can be hit, but it''s long and confusing, so I won''t bother posting it until I find a complete solution. Also, you want to find an angle to hit an object in a fixed time period. Sometimes, however, especially if you''re dealing with slow-moving objects and projectiles, the minimum amount of time to hit the target will increase. So it seems you aren''t looking for the angle for a set time; you''re looking for the minimum time AND the angle.

I''m trying to figure this one out, and, when (and if) I do, I''ll post back here.

Share this post

Link to post
Share on other sites
Thanks. I been working on a formula that uses fixed velocity (the bullet's velocity is 2x the enemy's velocity) but it's HUGE. If I solve it, i'll defenitely post it too.r

Is there some sort of math/calculs that deals with these types of problems?

Edited by - kingpin on October 20, 2001 7:48:25 PM

Share this post

Link to post
Share on other sites
If the enemy is at A and the bot is at V , and the enemy moves with a velocity VA while the projectile has a velocity VV , then

A + (VA * t) = V + (VV * t)
where t is the time necessary to intersect.
t = (A - V ) / (VV - VA )

If t < 0, there is no solution. If t > THRESHOLD (where THRESHOLD is an application defined limit to the temporal interval in which it is desired that the particles intercept), then the bot should ignore the enemy.

B is now A + (VA * t) or V + (VV * t). The desired angle is cos-1( VA * VB) (dot product).

I think that covers most cases. Please post if you discover any flaws.

Share this post

Link to post
Share on other sites
If you''re working in 3D with a flat plane you don''t need to use Sine or Cos. Even if your height varies (aiming for a cliff or something) it can still be done, I just havn''t figured out the general equation yet.

First figure out how fast you want to take out your target in seconds. Figure out where the target will be in that time based on it''s current position and velocity. Multiply that number by your gravity (9.8 typically) and that''s the vertical force you need to keep it up in the air for that time.

To figure out the x and z force needed you use the following:


(destx-currx)/totaldistance*force = xforce
(desty-curry)/totaldistance*force = yforce

That should get you missle to the target on time. You should limit force to make it somewhat of a challenge.

every frame calculate the current position with

x = xpos + xforce * t
y = ypos + yforce * t
l = ypos - zforce * t + gravity * t * t

where xpos and ypos is your original position


[Icarus Independent | Jump Down The Rabbithole | Tombstone: Vendetta ]

Share this post

Link to post
Share on other sites
Here''s some source in QuickBASIC which I''m using to test my formulas before popping them into my DX project. If you don''t have QB you can download it at my site in the tricks section.



INPUT "z force ", szforce

gravity = 10

FOR dest = 16 TO 22 * 16 STEP 16

zforce = (szforce * dest / 320) * gravity / 10
maxtime = zforce / gravity
xforce = dest / maxtime
maxheight = zforce * (maxtime / 2) - gravity * (maxtime / 2) * (maxtime / 2)

FOR x = 0 TO 640 STEP 16
LINE (x, 0)-(x, 480), 7
LINE (0, x)-(640, x), 7

LOCATE 2, 1: PRINT "xforce "
LOCATE 5, 1: PRINT "zforce "
LOCATE 8, 1: PRINT "maxtime "
LOCATE 11, 1: PRINT "max height "

LINE (100 + dest / 16, 48)-(100 + dest / 16, 48 - xforce / 5), 4
LINE (100 + dest / 16, 96)-(100 + dest / 16, 96 - zforce / 5), 4
LINE (100 + dest / 16, 144)-(100 + dest / 16, 144 - maxtime), 4
LINE (100 + dest / 16, 192)-(100 + dest / 16, 192 - maxheight / 2), 4
LINE (0, 300 - maxheight)-(640, 300 - maxheight), 14

xpos = 0
ypos = 300
t = 0
x = 0

LINE (dest, 280)-(dest, 320), 14

PSET (0, 300), 15

y = ypos - zforce * t + gravity * t * t

WHILE x < dest AND t < maxtime AND y <= ypos

x = xpos + xforce * t
y = ypos - zforce * t + gravity * t * t
LINE -(x, y), 15

LINE (x, y - 10)-(x, y + 10), 12

PSET (x, y), 15

t = t + 1 / 16


GOTO start

[Icarus Independent | Jump Down The Rabbithole | Tombstone: Vendetta ]

Share this post

Link to post
Share on other sites
Let me clarify the problem. The pic below is just an example to test
the algorithm (if there's one).

In the picture, B is the bot, E is the enemy, and T is the target.

Point B = (0,0)
Point E = (3, sqrt(12)/2)
Point T = (2, sqrt(12)
Ev (Enemy Velocity) = 1
Bv (Bot Velocity) = 2
Angle e (enemy heading) = 120°
Angle b (bot heading) = 60°

The text in black is what's known and the blue text is unknown. The
goal is to find Angle b (60°).

Point T can be anywhere from Point E to infinity, but must be along
the Vector E. So Angle b must be >= 30° to < 120°.

Well now that the problems set up, in this example, to prove that
E and B will meet at point T:
[where t = time]

Any point along Vector E at time (t) can be represented by:
E' = [ cos(120°)(Ev)(t) + Ex, sin(120°)(Ev)(t) + Ey ]

And for Vector B:
B' = [ cos(60°)(Bv)(t) + Bx, sin(60°)(Bv)(t) + By ]

Bx' = Ex'
[where t = time]

cos(60°)(Bv)(t) + Bx = cos(120°)(Ev)(t) + Ex
(.5)(2)(t) + 0 = (-0.5)(1)(t) + 3
t = -0.5(t) + 3
1 = -0.5 + (3/t)
(1.5/3) = 1/t
2 = t

Well it checks out, but what if Angle b is unknown?
[where b = Angle b, and t = time]

Bx' = Ex'
cos(b)(Bv)(t) + Bx = cos(120°)(Ev)(t) + Ex
cos(b)(2)(t) + 0 = cos(120°)(1)(t) + 3
cos(b)(2t) = -0.5t + 3
cos(b)(2t) - 3 = -0.5t
cos(b) - 3/2t = -1/4
cos(b) + 1/4 = 3/2t
(2/3)(cos(b) + 1/4) = t
... is there a way to solve for Angle b?

Edited by - kingpin on October 22, 2001 8:40:51 PM

Share this post

Link to post
Share on other sites

  • Advertisement