本文介绍了飞船推进的AI:控制在x = 0和v = 0处着陆的力的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须编写AI才能控制游戏中飞船的许多推进喷气机.

为简单起见:-
让空间为一维.
飞船是一个点,只有1架喷气机.

规则和问题

xva是飞船的位置,速度和加速度.
假设F是施加在船上的喷射力.

我知道宇宙飞船的质量m,比如说m = 1.

以下是摘要:-

acceleration = F/m;
v = vOld + acceleration*timestep;
x = xOld + v*timestep;

目标是将船以0速度降落到某个位置:-x = 0和v = 0.

AI可以加速"或减速"喷气机:-

F+=flexibility;
or
F-=flexibility;

AI可以访问当前的xvF. AI也可以缓存它.

我应该如何编程AI?

我可怜的解决方案

想法1:最后,x应该= 0.

假设a是常量:-

(current x) + (current v) * t + 1/2 * a * t * t = 0

t是一个魔幻数字-制造飞船的x = 0需要多少时间.

想法2:最后,v应该= 0.

(current v) + a*t = 0

我混合了两种想法:-

如果|x|>=thresholdX->使用提示1
如果|x|~0->使用提示2
之间-> 2个想法的平均权重

在这里,thresholdX是另一个魔术数字.
我从等式中使用a来找到合适的F. (F=ma)

这是结果:-


该图很吵,因为质量是由另一个AI近似的,并且存在一些小的随机外力.

如果有人要求,我可以发布我的C ++代码(〜100行).

解决方案

首先-您是打算降落在有质量的物体上,还是只是在太空中的某个任意定点停下来?您的问题是土地",所以我假设是前者,在这种情况下,您还需要考虑重力.要做起来应该很容易:F_actual = F_engine - F_gravity.

第二-您在现实生活中将如何做?现实中的飞行员希望在修剪"状态下将飞机修剪"在滑坡"上(很早到达跑道),以便在理想条件下(无风等),飞机可以不受控制地降落输入(我在简化一点,而忽略了耀斑等)

对于一枚火箭,我可能想让自己处于这样一种情况,即在地面上某个安全高度处,我的下降速度是这样的:在发动机以某个恒定功率运行的情况下,火箭会落在地面上本身,除了在触地得分时杀死引擎之外,我没有其他投入. (实际上,我希望飞行系统能让我在触地时自动杀伤武器.)

要查看其工作原理,只需反向运行问题即可.从x=0, v=0开始,与a=some constant and reasonable acceleration that the engine can produce一起,绘制随着火箭上升而随时间变化的x和v.显然,v=at(一行)和x是这些值的总和(抛物线).

那抛物线是你的滑坡".现在,您的问题不再是试图同时获得x=0v=0(x不会变成负数),而是变成如何在安全高度打滑坡?".因此,您的逻辑将类似于:

  1. 如果x = 0,请杀死引擎.
  2. 否则,如果您在滑坡上,则将发动机功率设置为所需的(恒定)减速度.坐下来等物理为您完成所有艰苦的工作.
  3. 否则,如果x< min_approach_height并且您不在滑坡上,要用力燃烧以爬上去.
  4. 否则,请调整发动机功率以达到滑行坡度.

一些注意事项:

  1. 滑坡"是指水平运动.我只是在用这个词来比喻固定翼飞机.我的意思是vx的图,它允许常数a产生柔和的触地,而无需其他控制输入.
  2. 您要降落的身体有气氛吗?如果是这样,您的火箭将具有最终速度,在这种情况下,逻辑将简化为:以足够快的速度进入大气层,以使最终速度达到滑行坡度以上.等待滑坡.当您上坡时,以恒定功率点火发动机.亲吻地面时杀死引擎.
  3. 直到现在,我仍然忽略了近似"质量和随机外力".只要这些距离不会使您离滑行斜坡太远,对功率的细微调整就会使您回到滑行斜坡.下降时不断进行这些更正.如果您偏离坡度太远,请使用MAX BURN,然后重试.
  4. 顺便说一句,如果不是因为那些随机效应,这种滑坡方法使使用只有两个设置(恒定减速功率和关闭)的发动机轻轻着陆变得相当简单.
  5. 我还没有解决您的问题,只是把它变成了另一个问题-但是,解决这个新问题应该会使您的游戏更加逼真(希望改善沉浸感).另外,这个问题可能比原来的问题更简单(请参见上面的注释2和4).而且,最后,尽早设置下滑坡,然后仅进行较小的校正调整就意味着您的AI不必处理极端情况或提供极端控制输入.

Hmmmm-即使编辑后,该帖子也相当长.我想我应该马上停下来.

I have to code AI to control many propulsion jets for a spaceship in a game.

For simplicity :-
Let the space be 1D.
Spaceship is a point and there is only 1 jet.

Rule and problem

Let x, v and a are position, velocity, acceleration of the spaceship.
Let F be the force of jet that apply to the ship.

I know mass m of the spaceship, let's say m=1.

Here is a summary :-

acceleration = F/m;
v = vOld + acceleration*timestep;
x = xOld + v*timestep;

The objective is to land the ship on a certain position with 0 velocity :- x=0 and v=0.

AI can "accelerate" or "decelerate" the jet :-

F+=flexibility;
or
F-=flexibility;

AI can access current x, v and F. AI can also cache it.

How should I program the AI?

My poor solution

Idea 1 : At last, x should = 0.

Assume that a is constant :-

(current x) + (current v) * t + 1/2 * a * t * t = 0

t is a magic number - how much time its require to make the spaceship's x=0.

Idea 2 : At last, v should = 0.

(current v) + a*t = 0

I mixed both ideas :-

if |x|>=thresholdX --> use idea 1
if |x|~0 --> use idea 2
in between --> weight average of 2 ideas

Here, thresholdX is another magic number.
I use a from the equation to find appropriate F. (F=ma)

Here is a result :-


The graph is noisy because the mass is approximated by another AI, and there are some small random external forces.

If anybody asks, I can post my C++ code (~100 lines).

解决方案

Firstly - Are you planning on landing on a body (which has mass), or just coming to a stop at some arbitray point in space? Your question says "land", so I'm assuming the former, in which case you need to factor gravity in as well. Which should be easy enough to do: F_actual = F_engine - F_gravity.

Secondly - How would you do this in real life? Real-life pilots want to "establish" their aircraft on a "glide slope" (well before reaching the runway), with the aircraft "trimmed" so that in ideal conditions (no wind, etc) the plane could land itself with no control inputs (I'm simplifying a bit, and ignoring flare etc.)

For a rocket, I would probably want to get myself into a situation such that at some safe height above the ground, my descent rate is such that with the engine running at some constant power, the rocket would settle to the ground by itself, with no extra input from me except killing the engine at the point of touchdown. (Actually, I would hope that the flight system allowed me to arm an auto-kill on touchdown.)

To see how this would work, just run the problem in reverse. Starting at x=0, v=0, with a=some constant and reasonable acceleration that the engine can produce, plot the x and v over time as the rocket ascends. Obviously, v=at (a line) and x is a summation of those values (a parabola).

That parabola is your "glide slope". Now rather than trying to get x=0 and v=0 at the same time (without x ever becoming negative), your problem has become "How do I hit the glide slope at a safe height?". So your logic would be something like:

  1. If x=0, kill engine.
  2. Else, if you are on the glide slope, set engine power for desired (constant) decel. Sit back and wait while physics does all the hard work for you.
  3. Else, if x < min_approach_height and you are not on the glide slope, burn hard enough to climb.
  4. Else, adjust engine power to reach the glide slope.

Some notes:

  1. By "glide slope", I don't mean to imply horizontal motion. I'm just using the term by analogy to fixed wing aircraft. What I mean is the plot of v against x that allows a constant a to produce a gentle touch-down with no additional control inputs.
  2. Does the body you're landing on have an atmosphere? If so, your rocket would have a terminal velocity, in which case the logic simplifies to: enter the atmosphere fast enough to hit terminal velocity above the glide slope. Wait for the glide slope. As you hit the slope, fire the engines at constant power. Kill the engine as you kiss the ground.
  3. Until now, I've disregarded the "approximated" mass and the "random external forces". As long as these don't lead you too far away from the glide slope, small adjustments to power should bring you back to the slope. Make these corrections continuously as you descend. If you ever deviate too far from the slope, MAX BURN and try again.
  4. Incidentally, if it weren't for those random effects, this glide slope approach makes it fairly simple to land gently with an engine that has only two settings, constant deceleration power and off.
  5. I haven't solved your problem, just turned it into a different problem - BUT, solving this new problem should make your game a little more realistic (hopefully improving immersion). Also, this problem may end up being simpler than the original (see notes 2 and 4 above). And, lastly, setting up on the glide slope early, and then only making small correction adjustments means that your AI doesn't have to handle extreme situations, or provide extreme control inputs.

Hmmmm - even after editing, this post is quite long. I think I should stop right about..... now.

这篇关于飞船推进的AI:控制在x = 0和v = 0处着陆的力的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 02:53