# Perfect Prediction

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

## Recommended Posts

I'm working on an AI system for a modification of a game right now and I need to write out a perfect prediction algorithm for projectiles. I have all the data needed to write out a good prediction system but I just don't know enough about physics to figure it out on my own. Think 'Unreal Tournament' / 'Quake' when you think about the game I'm working with, it's a big 3D world FPS game.

Known Data (Players)
-Velocity 3D Vector
-Origin 3D Vector

Known Data (Projectile)
-Velocity 3D Vector
-Shoot Origin Vector

Known Data (World)
-Gravity Float

##### Share on other sites
What do you need to predict? Do you need to predict if it impacts and/or the time of impact?

##### Share on other sites
What is easy to do is predicting the position of the projectile/player at a given time (assuming no additional "forces" besides gravity).

In case of a straight moving projectile (ie. one that isn't affected by gravity). Position can be calculated as:
[formula]x(t) = x_0 + (t-t_0)v_0[/formula]

In case of an object that is affected by gravity you get an additional acceleration term:
[formula]x(t) = x_0 + (t-t_0)v_0 + 0.5(t-t_0)^2g[/formula]
where g is the gravity vector g = (0,-10,0) (assuming the y-axis is the "up" direction).

##### Share on other sites

What is easy to do is predicting the position of the projectile/player at a given time (assuming no additional "forces" besides gravity).

In case of a straight moving projectile (ie. one that isn't affected by gravity). Position can be calculated as:
[formula]x(t) = x_0 + (t-t_0)v_0[/formula]

In case of an object that is affected by gravity you get an additional acceleration term:
[formula]x(t) = x_0 + (t-t_0)v_0 + 0.5(t-t_0)^2g[/formula]
where g is the gravity vector g = (0,-10,0) (assuming the y-axis is the "up" direction).

I know that t = time and v = velocity and g = gravity but I don't know any of those other variables. I'm good at math but I never enjoyed it so I didn't pay much attention in school unfortunately. I'm trying to predict the 3D vector where the AI player needs to aim, assuming the player continues running in a straight line obviously, for the projectile to hit him every time. I am looking for 'perfect' prediction without any kind of human mistake factors to make the bots as good as they can possibly be. Some projectiles DO drop due to gravity but others don't by the way.

##### Share on other sites
The variables with the zeroes are just the start values. So [formula]t_0[/formula] is the time at which a projectile was fired with velocity [formula]v_0[/formula] at position [formula]x_0[/formula].

The functions I gave describe the trajectories. So the problem is to find a trajectory [formula]x_{bullet}(t)[/formula] such that [formula]x_{bullet}(t_{hit}) = x_{player}(t_{hit})[/formula]. If you just write this down the equations will be linear in [formula]v_0[/formula], quadratic in [formula]t_{hit}[/formula] and generally be under determined. So you need additional constraints which I guess will usually be that [formula]|v_0|[/formula] is some scalar value. So sadly the whole equation system ends up being non linear. So from a practical point of view you are probably best served by approximating the optimal trajectory with some iterative method. Something along the lines: estimate the bullets travel time and calculate the targets position at that time. Find the trajectory to that position for the bullet. See how far off the actual travel time of the bullet is. If it is small enough stop, otherwise use that time as the new estimation for time and repeat.

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 11
• 23
• 38
• 75