2D游戏:火在一个移动的目标,炮弹和单位的predicting路口炮弹、路口、目标、单位

2023-09-08 09:05:42 作者:甜ぃぅおか

好了,这一切都发生在一个很好的和简单的2D世界...:)

Okay, this all takes place in a nice and simple 2D world... :)

假设我有一个静态目标A位置者,并在BPOS与bVelocity线性运动物体B,和一个弹药轮速度Avelocity ...

Suppose I have a static object A at position Apos, and a linearly moving object B at Bpos with bVelocity, and an ammo round with velocity Avelocity...

我将如何找出一个有投篮,命中B,考虑到B的线速度和A的弹药速度的角度?

How would I find out the angle that A has to shoot, to hit B, taking into account B's linear velocity and the speed of A's ammo ?

眼下目的的在对象的当前位置,这意味着,由时间我的弹丸到达那里的单元已移动到更安全的位置:)

Right now the aim's at the current position of the object, which means that by the time my projectile gets there the unit has moved on to safer positions :)

推荐答案

首先旋转轴,使AB是垂直的(做旋转)

First rotate the axes so that AB is vertical (by doing a rotation)

现在,拆分B的速度向量进x和y分量(说的Bx和By)。你可以用它来计算矢量的X和Y组件,您需要拍摄的。

Now, split the velocity vector of B into the x and y components (say Bx and By). You can use this to calculate the x and y components of the vector you need to shoot at.

B --> Bx
|
|
V

By


Vy
^
|
|
A ---> Vx

您需要 Vx的= Bx的 SQRT(Vx的* Vx的+ Vy速度* VY)=弹药的速度

这应该给你你需要在新的系统中的载体。变换回到旧体制和你做(做旋转在另一个方向上)。

This should give you the vector you need in the new system. Transform back to old system and you are done (by doing a rotation in the other direction).