We don’t allow questions seeking recommendations for software libraries, tutorials, tools, books, or other off-site resources. You can edit the question so it can be answered with facts and citations.
Closed 8 years ago.
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
接受
或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
发布评论
评论(4)
Pymunk 是您可能想了解的另一个有前景的工具。
Pymunk is another promising one that you might want to take a look at.
试试pyODE,它是开放动态引擎的python绑定。
您可以在此处找到更多信息
Try pyODE, it is the python binding of open dynamic engine.
You can find more information here
您只需要基本的物理运动学方程即可。即使问题已经得到解答,如果我是你,我仍然会手动完成,因为使用库似乎有点矫枉过正。开始速度方程:
从那里,我们积分以找到位置:
您的跳跃正在计算角色的 y 位置,因此只需使用该方程来计算 y 位置和玩具的初始速度和加速度。标准重力加速度为 -9.8 米每秒^2(至少在地球表面上 - 不同的行星有所不同)。无论你的角色在什么位置,都从初始位置开始,如果地面对你来说是 0,则从 0 开始。
因此:
选择一个初始速度 v 值来提供跳跃开始时的向上运动,t 应该是自他开始跳跃以来经过的游戏时间。
您只需要一行代码即可完成此操作,无需任何库!
编辑:处理着陆时要做什么。
所以在现实世界中,加速度是由不平衡力引起的。重力始终作用在您身上,但是当您站在地面上时,重力会被地面的“法向力”抵消并抵消。只要你站立的地面足够坚固,能够支撑你的体重,地面就会向上推并抵抗重力,你就不会加速向下。因此,在游戏中,如果您实际上并未模拟力,只需在角色接触地面时将加速度从 -9.8 更改为 0 即可。如果地面平坦,则当
位置=初始位置
时,跳跃结束The basic physics kinematic equations are all you need. Even though the questions was already answered, if I were you, I'd still do it by hand just because using a library seems like overkill. Start the equation for velocity:
From there, we integrate to find position:
Your jump is looking to calculate the y position of the character, so just use that equation to calculate y position and toy with initial velocity and acceleration. Standard acceleration due to gravity is -9.8 meters per second^2 (at least on the surface of the earth - it's different son different planets). Start with initial position whatever your character is at, or 0 if the ground is 0 to you.
So:
Pick an initial velocity
v
value to provide the upward movement when the jump starts, and t should be the elapsed game time since he started jumping.You only need one line of code to do this, no libraries necessary!
EDIT: dealing with what to do when you land.
So in the real world, acceleration is caused by unbalanced forces. Gravity is always acting on you, but when you're standing in the ground, it's being countered and canceled out by the "normal force" of the ground. As long as the ground you're standing on is strong enough to support your weight, the ground will push back up and counter gravity and you will not accelerate downward. So in your game, if you're not actually simulating forces, just change the acceleration from -9.8 to 0 when your character is touching the ground. If the ground is flat, your jump ends when
position = initial position
根据ODE网站的安装说明,ODE包本身现在包含基于 CPython 的 Python 绑定;并且 pyODE 绑定被认为已过时。安装说明包含在上页中。
默认情况下,这是针对 Python 2 的,但我也能够以最少的工作量 (Mac OS X) 使此绑定适用于 Python 3。我什至可以运行教程。
这可能超出了主题,但仅供记录,以下是我必须更改的内容:
#defines
来更改OpCode.h
>sqrt、sin
、cos
、asin
和acos
(第 33-37 行,文件版本:3月20日, 2001)。这是我需要的一个丑陋的黑客,因为如果没有这个 ODE 本身就无法使用双精度算术进行编译,如果我们可以信任 ODE 页面上的文档,则需要与 python 绑定一起使用。我必须通过在第 18 行后添加以下行来更改
setup.py
:要运行教程,请在
demos
目录中我用过<前><代码>$ 2to3 -w *.py
它。
According to the ODE website's installation instructions, the ODE package itself now contains Python bindings based on CPython; and the pyODE bindings are considered obsolete. Installation instructions are included in the above page.
By default this is for Python 2, but I was able to make this binding work with Python 3, too, with a minimum amount of work (Mac OS X). I could even run the tutorials.
This might be out of topic, but just for the record, here is what I had to change:
OpCode.h
by uncommenting the#defines
forsqrt
,sin
,cos
,asin
andacos
(lines 33-37, file version: March 20, 2001). This is an ugly hack that I needed because without this ODE itself did not compile with double precision arithmetic, which one needs to use with the python bindings if we can trust the documentation on the ODE page.I had to change
setup.py
by adding the following lines after line 18:To run the tutorials, in the
demos
directory I usedThat's it.