Player moves faster with higher deltaTime

别来无恙 提交于 2019-12-13 05:24:36

问题


Here's the first version, where I have a delta of 1/60: http://jsfiddle.net/ocdrd0uy/

Here's the second version, where the only thing I changed was the delta to 1/20: http://jsfiddle.net/ocdrd0uy/1/

var delta = 1 / 60; --> var delta = 1 / 20;

I simply timestep like this:

x = x + v * dt * 0.5
v = v + (F * 1/m) * dt
x = x + v * dt * 0.5

Why does the player move faster with higher delta?


回答1:


It's quite logical that when your delta decrease, the speed will increase.
After you do your 2 half-step integration, you clear the force.
So, since you don't set it again elsewhere, what you are doing is applying the force (to change the velocity) during delta on the first tick, then no more force is applied.
So the speed after first tick changes depending on the delta, then speed remains at that level.

To correct that, i'll have to know what you're trying to model.
If you're trying to model an initial 'punch' that is due to a force applied during a very short time, just apply F during punchDuration to the speed -which is very similar to setting an initial velocity-.



来源:https://stackoverflow.com/questions/28262448/player-moves-faster-with-higher-deltatime

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!