0

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?

  • as a sidenote, you can use `requestAnimationFrame` instead of `setTimeout` to better align the rendering of your content with the rendering of the browser. – Iftah Feb 01 '15 at 15:23

1 Answers1

0

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-.

GameAlchemist
  • 18,995
  • 7
  • 36
  • 59
  • Yes, I want to get a punch effect that will punch the same hardness every time. So I can do: `player.force.add(vec.div(new vec(2000, 0), delta))` or simply `player.vel.add(new vec(2000, 0))`? –  Feb 02 '15 at 15:17
  • Using an initial velocity or force + duration is pretty much the same. But if you use a punch force, you must handle it differently from constant forces (== handle punch with their own duration, vs constant forces that uses the current delta and are *not* cleared on each cycle (expl: gravity). ). I'd use the velocity way. – GameAlchemist Feb 02 '15 at 18:36