月球着陆器游戏需要哪些数学知识?
我想制作一个游戏来学习 cocos2d
。 月球着陆器
是我想到的第一个练习。任何所需物理计算的指针/源代码/教程都将受到赞赏。谢谢!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
我想制作一个游戏来学习 cocos2d
。 月球着陆器
是我想到的第一个练习。任何所需物理计算的指针/源代码/教程都将受到赞赏。谢谢!
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(6)
你需要这样的东西:
您将从初始条件开始,并循环多个时间步长。在每个步骤结束时,您将检查位置和速度。如果表面上方的 y 位置为零或负值,您就会着陆。如果速度大于临界 y 值,您就会发生碰撞;低于临界值意味着安全、软着陆。
您将以数值方式求解牛顿运动方程。在您的情况下,它是四个耦合的一阶常微分方程:x 和 y 方向上的速度变化率以及 x 和 y 方向上的位置变化率。如果推进器就位,您将添加另一个燃料质量守恒方程。
如果假设没有 x 分量,则可以消除两个方程:月球着陆器垂直于表面移动,推进器力仅在垂直方向上具有非零分量。如果这是真的,那么你就只剩下三个方程了。
您将进行时间步进,因此最好阅读显式欧拉或隐式五阶龙格库塔等积分技术。
一个具有挑战性的问题——并非微不足道。祝你好运。
You'll need stuff like this:
You'll start with initial conditions and loop over a number of time steps. At the end of each step you'll check the position and velocity. If the y-position above the surface is zero or negative you'll have landed. If the velocity is greater than a critical y-value you'll have a crash; less than the critical value means a safe, soft landing.
You'll solve Newton's equations of motion numerically. In your case it's four coupled, first order ordinary differential equations: rate of change of velocity in x- and y-directions and rate of change of position in x- and y-directions. If you have the thrusters in place you'll add another equation for conservation of mass for the fuel.
You can eliminate two equations if you assume that there are no x-components: the lunar lander moves perpendicular to the surface, the thruster force only has a non-zero component in the vertical direction. If that's true, you're down to three equations.
You'll do time stepping, so it'll be good to read up integration techniques like explicit Euler or implicit 5th order Runge-Kutta.
A challenging problem - not trivial. Good luck.
月球着陆器游戏所需的数学非常简单。 牛顿运动定律就是您真正需要的一切 - 只需拿起一本基础物理教科书即可。你应该在第一章之后就设置好了。系统中只有两种力输入:重力和来自发动机的推力。只需计算垂直度和垂直度即可。运动的水平分量,并相应地为你的宇宙飞船设置动画。
The math you need for a lunar lander game is pretty straightforward. Newton's Laws of Motion are all you really need - just pick up a basic physics textbook. You should be set after the first chapter. There are only two force inputs in the system - gravity and thrust from the engines. Just calculate the vertical & horizontal components of the motion, and animate your spaceship accordingly.
物理学非常简单:http://csep10.phys.utk。 edu/astr161/lect/history/newtongrav.html
我假设您不会担心阻力或风,因此根据您的倾斜角度(用户输入),您将实现:
来源:http://en.wikipedia.org/wiki/Trajectory。你甚至可以通过简化它来逃脱惩罚。如果您不想变得超级精确,您可以执行类似
F=ma
的操作,其中 is 是您决定的重力加速度(地球上为 9.8 m/s²)。The physics are very simple: http://csep10.phys.utk.edu/astr161/lect/history/newtongrav.html
I assume you won't be worrying about drag or wind, so depending on your angles of inclination (user input), you'll be implementing:
Sourced from: http://en.wikipedia.org/wiki/Trajectory. You can even probably get away with simplifying it. If you don't want to be super-accurate, you can just do something like
F=ma
where is is whatever you decide the gravitational acceleration to be (9.8 m/s² on Earth).如果你的游戏是 2D 的,你不需要太多数学,你需要物理,特别是基本的牛顿运动。可能是大学简介或高中后期。数学是一些小学代数和高中早期的微积分。
如果你观察上下运动,那么你的船本质上是一个受到重力(常数取决于你的“月亮”)的物体,其发动机发出的力抵消了重力。您可以用它来确定加速度和速度。使用速度,您可以得出碰撞结果。左右运动更容易,因为如果你的月球没有大气层,你只需施加恒定的力。
如果你想要更真实的东西,你可以根据距表面的距离修改重力常数,并可以添加大气摩擦力(尽管它并不是真正的月球)。
如果您的游戏是 3D 模式,并且您的飞船除了底部推进器之外还有侧面推进器,那么您不仅可以进行位置运动,还可以进行旋转。这与刚体物理学有关。据我所知,涉及大学水平的微积分。
If your game is in 2D, You don't need much math, you need physics, Specifically basic Newtonian motion. Probably intro college or late high school. The math is some grade school algebra with early high school calculus.
If you look at up-down motion, then your ship is essentially an object that is exposed to a force of gravity (the constant depends on your "moon") negated by the force emitted by its engines. You can use that to determine acceleration and from there velocity. Using the velocity, you can do your collision-outcome. The left-and-right motion is easier, since if your moon has no atmosphere, you are merely applying a constant force.
If you want something more realistic, you can modify the gravity constant based on distance from the surface, and can add an atmospheric friction force (though it wouldn't really be our moon).
If your game is in 3D, and your ship has side thrusters in addition to bottom thrusters, then you would not only have motion in location but also rotation. That has to do with rigid body physics. AFAIK that involves college level calculus.
这可能有点过头了,但我建议您查看数值食谱 - 阅读有关常微分方程的章节。你甚至不需要学习整章;只是前几个部分。
This may be overkill, but I recommend looking at Numerical Recipes -- read the chapter on ordinary differential equations. You don't even need to study the entire chapter; just the first couple of sections.
在二维中,在每次刻度时,您想要将船舶的旋转推力与其旋转速度相加,将其旋转速度与其当前航向相加,通过将其航向的正弦和余弦与其主推进器输出相乘来计算推力矢量,然后添加该向量和重力向量(某个大小的直线向下向量)添加到其当前速度,并将其当前速度添加到其位置。如果计时器的滴答声足够小,那么除了检查飞行器是否与地面接触之外,这几乎就是您所要做的全部事情。试验你的推力和重力值的大小,直到你有一个可玩的游戏。
In two dimensions, on every time tick you want to add the ship's rotational thrust to its rotational velocity, add its rotational velocity to its current heading, compute a thrust vector by multiplying the sine and cosine of its heading by its main thruster output, add that vector and a gravity vector (a straight downward vector of some magnitude) to its current velocity, and add its current velocity to its position. If the timer ticks are small enough, that's pretty much all you have to do, other than check to see if the craft is in contact with the ground. Experiment with the magnitude of your thrust and gravity values until you have a playable game.