开发者

Predicting ball path - Artificial Intelligence

I'm implementing a simple Volleyball game using Box2D in Flash. I need to implement some AI for the CPU player. Let's call him Jack. So Jack needs to predict where's the ball gonna land after it has been hit by John, the human player. I have the following information :

  1. Initial Linear Velocity (both in x & y direction) of the ball when John hits it.
  2. The initial position of the ball when John hits it. (x & y coordinate values)
  3. The value of gravity.
  4. The value of y position of floor where's the ball's gonna fall.
  5. The angle at which John hits the ball.
  6. The ball follow a projectile trajectory.

So Jack needs to predict what would开发者_开发知识库 be the position (x value) of the ball when it hits the floor.

I think as the ball follows a projectile trajectory the problem might be seen same as that of - firing a cannon ball from some known initial position, known initial velocity with fixed gravity and predicting its landing spot. The y value of landing spot is also known. The air resistance is zero.

Is there any kind of mathematical equation which might help to predict the x value of the landing spot? I took a look at some projectile equations but most of them take 'time' as a variable. I need to have a solution that doesn't involve this 'time' variable. Any kind of work-arounds for this problem would also be appreciated. Thank you! :)


If you have an equation for z (i.e. height) in terms of t, then you need to solve that for z = 0 to get the value of t when the ball lands. You can then feed that back into the equations for x and y.


You have to solve z(x)=0 with this equation: g is gravity, v0 is initial speed along x axis, a is the angle.

Predicting ball path - Artificial Intelligence

When you solve it, it gives the length of the segment joining start point and end point (choose one end point depending on the hit direction).

Predicting ball path - Artificial Intelligence

If you're in 3D, you'll have to do some projections to remove the 3D part of the problem, and keep only two axis.


Initial Linear Velocity (both in x & y direction) of the ball when John hits it.

The initial position of the ball when John hits it. (x & y coordinate values)

The value of gravity.

And the direction - negative y-direction, of course. 32.2 ft/sec^2 = 9.8 m/sec^2, right?

The value of y position of floor where's the ball's gonna fall.

It'll hit at y = 0 if no other player touches it.

The angle at which John hits the ball.

I think it'd be better to say something about the force John applies to the ball and for how long.

The ball follow a projectile trajectory.

No, you have no such thing. This is what you're trying to solve.

What you have is Newton's law: F = ma, where force is the vector of force applied to the ball, m is the mass of the ball, a is the acceleration vector applied to the ball.

The ball is accelerated by gravity in the negative y-direction, of course, but you're forgetting the force vector that the player applies when the ball is struck.

Once you have those you solve two coupled ODEs forward in time.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜