简体   繁体   English

如何为射弹获得一个角度,使其在分解重力的同时击中矢量2目标

[英]How to get an angle for a projectile such that it will hit a vector 2 target while factoring in gravity

I have an enemy that can shoot projectiles, but my issue is I am trying to find the angle required to hit the player, but the projectile has to be shot at an exact velocity (ie can't shoot the projectile more slowly). 我有一个可以射击射弹的敌人,但我的问题是我试图找到击中玩家所需的角度,但射弹必须以精确的速度射击(即不能更慢地射击射弹)。 I have tried the range equation, but I can not simplify it such that I get the theta (angle), that factors in the y distance, the x distance, the velocity, and the gravity. 我已经尝试了范围方程,但我无法简化它,因此我得到了θ(角度),即y距离,x距离,速度和重力的因子。

Sorry for the sprawling question, Teh Cosmic Sloth 对不起庞大的问题,Teh Cosmic Sloth

Well... You have: D - distance to target 嗯......你有:D - 目标距离

g = 9.8 - g- force g = 9.8 - g-力

v - your firing velocity v - 你的射击速度

Your velocity along X is v*cos(a) 你沿X的速度是v * cos(a)

Your velocity along Y is v*sin(a) 你沿Y的速度是v * sin(a)

you need to travel distance D, hence your time of flight is t = D/v*cos(a) 你需要行驶距离D,因此你的飞行时间是t = D / v * cos(a)

in that time you need to reach the maximum height of your flight and fall back. 在那个时候你需要达到你的飞行的最大高度并回落。 At maximum point your vertical speed will be 0, at the end of flight your vertical speed will equal to the starting vertical speed, if we ignore the air resistance. 在最大点,您的垂直速度将为0,在飞行结束时,如果我们忽略空气阻力,您的垂直速度将等于起始垂直速度。

So, bearing in mind that the equation for speed is v = acc*t (where acc is g for you) t = v/acc. 所以,请记住,速度方程是v = acc * t(其中acc是g)t = v / acc。 In your case you have to drop speed to 0 and get it back to original, so you have factor of 2. 在您的情况下,您必须将速度降至0并将其恢复为原始状态,因此您的因子为2。

t = 2*(v*sin(a)/g) t = 2 *(v * sin(a)/ g)

Lets sum it up: 让我们总结一下:

t = D/v*cos(a) t = D / v * cos(a)

t = 2*(v*sin(a)/g) t = 2 *(v * sin(a)/ g)


2*(v sin(a)/g) = D/v cos(a) 2 *(v sin(a)/ g)= D / v cos(a)

You know everything but angle a. 除了角度之外,你知道的一切。

So, by doing some variable transfers you get 所以,通过做一些变量转移你得到

2sin(a) cos(a) = D g / v^2 2sin(a) cos(a)= D g / v ^ 2

which is: 这是:

sin(2a) = D*g/v^2 sin(2a)= D * g / v ^ 2

2a = arcsin( D*g/ v^2) 2a = arcsin(D * g / v ^ 2)

So, this must be the answer. 所以,这一定是答案。

a = arcsin( D * g / (v^2) ) / 2 a = arcsin(D * g /(v ^ 2))/ 2

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM