预测球路 - 人工智能

发布于 2024-11-06 14:24:36 字数 538 浏览 4 评论 0原文

我正在 Flash 中使用 Box2D 实现一个简单的排球游戏。我需要为 CPU 玩家实现一些 AI。我们就叫他杰克吧。因此,杰克需要预测球被人类玩家约翰击中后会落在哪里。我有以下信息:

  1. 约翰移动时球的初始线速度(x 和 y 方向) 击中它。
  2. 约翰击球时球的初始位置。 (x 和 y 坐标 值)
  3. 重力值。
  4. 球即将落下的地板的 y 位置值。
  5. 约翰击球的角度。
  6. 球遵循抛射轨迹。

因此,杰克需要预测球落地时的位置(x 值)。

我认为当球遵循射弹轨迹时,问题可能与从某个已知的初始位置、已知的初始速度和固定重力发射炮弹并预测其着陆点的问题相同。着陆点的 y 值也是已知的。空气阻力为零。

是否有任何数学方程可以帮助预测着陆点的 x 值?我查看了一些射弹方程,但大多数都将“时间”作为变量。我需要一个不涉及这个“时间”变量的解决方案。对于此问题的任何类型的解决方法也将不胜感激。谢谢你! :)

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! :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

那小子欠揍 2024-11-13 14:24:36

如果您有一个以 t 表示的 z(即高度)方程,那么您需要求解 z = 0 以获得球落地时 t 的值。然后,您可以将其反馈到 xy 的方程中。

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.

掩饰不了的爱 2024-11-13 14:24:36

您必须使用以下方程求解 z(x)=0:
g 是重力,v0 是沿 x 轴的初始速度,a 是角度。

z 与 x 变量的方程

当你求解它时,它给出了连接起点和终点的线段的长度(选择一个终点取决于击打方向)。

Resolution

如果您处于 3D 环境中,则必须进行一些投影来消除问题的 3D 部分,并且只保留两个轴。

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

Equation of z with x variable

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).

Resolution

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.

海螺姑娘 2024-11-13 14:24:36

初始线速度(x 和 y 方向)
约翰击球时球的方向)
它。

球的初始位置
约翰击中了它。 (x 和 y 坐标
值)

重力值。

当然,方向是负 y 方向。 32.2 ft/sec^2 = 9.8 m/sec^2,对吧?

楼层的y位置值
球会落到哪里。

如果没有其他玩家触及它,它将在 y = 0 处击中。

约翰击球的角度。

我认为最好谈谈约翰对球施加的力以及持续的时间。

球跟随抛射物
轨迹。

不,你没有这样的东西。这就是你要解决的问题。

牛顿定律:F = ma, 其中力是施加到球上的力的矢量,m 是球的质量,a 是施加到球上的加速度矢量。

当然,球会因重力而在负 y 方向上加速,但您忘记了球员击球时施加的力矢量。

一旦你有了这些,你就可以及时求解两个耦合的常微分方程。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文