Jump to content
  • Advertisement
Sign in to follow this  
Corrupted

Perfect Prediction

This topic is 2549 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'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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!