I have a very simple 2D game, similar to old-school Mario or Metroid. I'm having a lot of trouble figuring out the proper way to handle player jumping. I've tried several different methods. The first method being that as soon as the player presses the space bar, his position on the Y-Axis is automatically updated so that he is now 50 pixels higher. This didn't work, because his player model immediately jumped up instead of going for that smooth up/down look. The second method I tried was using a
Timer. With this, once the player pressed the space bar, his position on the Y-Axis would be incremented every x milliseconds. This also didn't work, for the exact same reason that the first way didn't work. It shot straight up without looking smooth. The last method I tried was a resemblance of my movement on the X-Axis. Instead of waiting for player input, the Y-Axis is constantly being added, but when the player isn't jumping, the
yVelocity = 0. When input does come in, an amount is added
yVelocity and the player jumps up. I didn't expect this to work, obviously, but it looked better.
So how do you apply jumping correctly? This is something that I've been struggling with for a while, and I just want to get it right. Please don't confuse this question like this question, as they're both different. I need an efficient way to handle jumping so that he looks smooth (as in one motion) going up and down. I can make his falling look good, just not the going up part. Can anybody explain to me how they make jumping look good?
Note: I wrote this question without code because I want a general description of how one might do it. If you do need code or extra details, or anything to understand the question, I'll be happy to add any extra details that you might need.