DarthMike / indielib-crossplatform

IndieLib is a cross-platform Game Graphics engine. Main focus is OpenGL ES 2.0 for mobile iOS operating system, and OpenGL desktop. **NOT SUPPORTED ANYMORE**
zlib License
61 stars 27 forks source link

How to move entities with the same speed on different PCs? #146

Closed SerhiiYashchuk closed 10 years ago

SerhiiYashchuk commented 10 years ago

I'm trying to implement jump physic for my game. While the character is jumping, his speed is reduced a bit. The problem is that the character jumps with different height every time.

Using getFrameTime() to get the right delta for movement works differently. I tried to use timer and move character with constant delta when timer reaches a time delta. In this case the height of jump looks the same but speed is different.

How can I make him to jump with the same height and speed?

DarthMike commented 10 years ago

Ideally you want to have a velocity defined in code. That will be constant or change depending on where the character will be in the jump height.

When it comes to position the sprite, simply calculate delta time as t - tLastFrame. Use this delta multiplied by the speed to move the character at the same speed.

To make him jump to same height I suggest either:

  1. Limit the height, then move downwards: Probably you don't want that
  2. Simulate the speed decrease when going up because of gravity.

To get a nice slowing down then falling (#2), needs a bit more work. Either simulating the gravity drag with a mathematical calculation, or hardcoding speeds at different heights (it's believed that's how original mario games had speeds calculated). You can easily simulate gravity drag by decreasing an amount to the speed every frame.

See these: http://www.gamedev.net/topic/490713-jump-formula/ http://www.rodedev.com/tutorials/gamephysics/ http://gamedev.stackexchange.com/questions/6618/analysis-of-mario-game-physics