Godot - 在不破坏物理的情况下加速游戏

Godot - Speed up the game without breaking physics

我正在制作一款足球模拟游戏,为此我为球员和球使用了普通的 2DBody 节点。但我希望能够加快游戏速度,而不破坏物理并获得其他结果。

为了加快游戏速度,我发现 Engine.time_scaleEngine.iterations_per_second 会影响游戏速度。

所以时间刻度的默认值 = 1 和 iterations_per_second = 60

通过设置 time_scale = 0.5,物理学似乎被打破了。至少我可以看到,它看起来不如正常速度自然。

当通过设置 time_scale = 0.5每秒迭代次数 = 120 时, 所以物理学似乎并没有崩溃。 但我真的无法判断这是否是 100% 正确的。 (还有 99% 没问题 ;-) )

有人知道另一种在不破坏物理的情况下加速游戏的方法,或者可以确认,修改time_scale和每秒迭代次数'打破物理学?

首先,Godot 文档说:

float time_scale - Controls how fast or slow the in-game clock ticks versus the real life one. It defaults to 1.0. A value of 2.0 means the game moves twice as fast as real life, whilst a value of 0.5 means the game moves at half the regular speed.

所以如果你想加快游戏时间,你应该增加那个值,而不是减少。据我所知,这个值会影响 delta 传递给 _physics_process(delta) 方法(以及其他引擎内部物理计算)的时间,并且 time_scale 作为该值的多人游戏。

物理引擎以固定时间步长运行,因此 iterations_per_second 会影响它,如文档所述:

int iterations_per_second - The number of fixed iterations per second (for fixed process and physics).

是的,修改两个值应该会得到更好的结果,因为增加iterations_per_second会使物理计算更频繁,这意味着更精确(我们称之为“时间细节” ”)。它还能“打破物理学”吗?是的,如果物理计算速度不足以跟上引擎迭代频率。在这种情况下,唯一的解决办法就是优化您的游戏。