Reputation: 453
I'm currently working on a remake of Super Mario World in C# with some friends for a school project.
We got jumping roughly working, at least it goes up and down... the thing is, well, see for yourself:
https://gyazo.com/f49886ea48a0653b801d6c0741709fea Here is an animated gif of the problem.
It boosts up extremely fast, almost instantly and then slowly glides down. I tried changing gravity and jumpboost values but even though I partially fixed the gliding, I keep almost teleporting up. I can't seem to smooth out the jumping...
Here is the full player class: http://pastebin.com/bCjCB2q8
I can't find the problem, maybe one of you could help me to see where I go wrong in my way of thinking?
Upvotes: 0
Views: 128
Reputation: 868
I would usually implement basic newtonian movement with accelleration and velocity (Vector2).
for every update, you start with Acceleration = Vecotr2.Down * Gravity; and you end with Velocity += Acceleration * gameTime; Position += Velocity * gameTime;
gameTime = total elapsed seconds since last update. This is important to let numbers for acceleration and velocity stay in a consistent frame that make sense for humans. Basicly acceleration is change in velocity per second, while velocity is change in position per second.
To jump, you set Acceleration.Y = JumpSpeed / gameTime; //JumpSpeed = desired upwards velocity. the / gameTime nulls out the * gameTime when calculating velocity.
Afraid this answer might be a bit thin. I can embelish when I get home from work... :)
Upvotes: 1