Just finished my platformer physics for my game. Thought I could help.
Not sure if the above way is most effective.
What I have is this:
Onground Boolean - onGround
Terminal velocity - tv
Jump power - jmp
Velocity vector (added to the position) - vel
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
| if() { vel.y = 0; } else
onGround = (vel.y == 0); if() onGround = false;
if(!onGround) if(vel.y < tv) vel.y++; if(jumping) vel.y = jmp; |
Okay, this code is not copied from mine so it may have a mistake, but you should find any possible mistake quickly.
There are some things that need to be polished with this, but do that according to your game.