本文介绍了如何计算移动物体的未来位置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个小游戏,我有一个光子鱼雷,它从船上朝目标发射.现在,由于鱼雷的速度很慢,因此如果飞船移动,该船将永远不会撞到任何目标,我想解决这个问题.我已经提出了多种理论,并规划了许多数学知识,以找出实现这一目标的最佳方法,最后我得出以下结论:

I am creating a little game and I have a photon torpedo which is being fired from a ship towards a target. Now as the speed of the torpedo is slow the ship will never hit any targets if they're moving and I want to fix this. I have drew up multiple theories and mapped out lots of mathematical stuff to find out the best way to accomplish this and in the end I deduced the following:

  1. 列表项
  2. 我找到了光子鱼雷到达目标所需要的时间.
  3. 我发现目标在鱼雷到达之前已经走了多远.
  4. 然后我找到目标的新位置与原始飞船之间的距离.
  5. 然后,这使我有机会使用余弦规则(SSS)来确定需要发射子弹以具有更高击中几率的弹道.

这是一个数字:

现在唯一的问题是我需要将a线旋转到正确的方向,因为默认情况下,它与c线平行,这使整个方程式混乱.有人能帮忙吗?另外,如果您能想到更好的方法来找到新职位,也非常欢迎您提出建议:)

Now the only problem that I need to rotate line a to the correct orientation as by default it's parallel to line c which messes up the entire equation. Can anyone help with this? And also if you can think of a better way to find the new position suggestions are very welcome :)

推荐答案

看起来游戏是二维的.现在,获取所有世界坐标:

Looks like game is in 2D. Now, taking all world coordinates:

Target Position: {xt, yt}
Target Velocity: {vxt, vyt}
Ship Position:   {xs, ys}

现在,假设您在方向{bx, by}上击中子弹,它是方向矢量或单位矢量.子弹的速度为sb.因此,在时间t'中,子弹和目标的空间坐标为:

Now, lets say you hit a bullet in direction {bx, by} it is a directional vector or unit vector. The bullet has speed sb. Therefore, in time t' spacial coordinates of bullet and target would be:

Target New Position: {xt + vxt*t', yt + vyt*t'}
Bullet New Position: {xs + bx*sb*t', ys + by*sb*t'} ( bullet starts from ship)

因为,这时子弹和目标都必须都在一个位置,所以我们可以说子弹已经击中了目标.因此,我们可以将新的目标位置替换为等于新的子弹位置(在时间t'之后):

Since, at this time both bullet and target must be at one location only then we can say bullet has hit the target. Therefore, we can substitute new target position to be equal to new bullet location (after time t'):

xt + vxt*t' = xs + bx*sb*t'
yt + vyt*t' = ys + by*sb*t'

正如我之前所说,bxby是方向矢量,因此bx^2 + by^2 = 1

As I said earlier, bx and by are directional vector, therefore bx^2 + by^2 = 1

(xt + vxt*t' - xs)/(sb*t') = bx
(yt + vyt*t' - ys)/(sb*t') = by
bx^2 + by^2 = 1

因此,在对它们进行平方和添加后,您将得到:

Therefore, after squaring and adding them, you will get:

(yt + vyt*t' - ys)^2 + (xt + vxt*t' - xs)^2 = (sb*t')^2

这是一个带一个变量的二次方程:t'求解它,然后您可以找到bxby.

This is a quadratic equation with one variable: t' solve it and then you could find bx and by.

这篇关于如何计算移动物体的未来位置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-04 04:27
查看更多