Player jumping?


(Ethan Smythe) #1

Hey guys

What is the best/easiest way to make a player jump?


(Jacob Albano) #2

This isn’t really a question about Flashpunk…Flashpunk doesn’t have any kind of physics system built in, so movement varies from game to game.


(Ultima2876) #3

Check this example project out, it has some jumping and other general platformer code you can learn from:


(Nate ) #4

This can be done in many different ways.

You are going to need at least a jump speed variable(preferably a constant) that gets applied to your player after a key check of some kind; as well as a gravity variable which will force your player back down to earth, unless you want to be able to jump and not come down.

Also the jump key check, and gravity should be implemented somewhere in your player update function.

Once this is set up you can get fancy and add more features like friction and such!

Hope this helped! That example that Ultima posted is a good crash course for the basics and even some particle emitting!


(Suyash Mohan) #5

You should Maintain 3 vectors: Position, Velocity and Acceleration

Initially set acceleration -ve in y-axis to simulate gravity

And Update these vectors at every frame like this

Position += Velocity

Velocity += Acceleration

(But if you are on ground, don’t update the y component of velocity and position)

Now when you need to jump, simply set the Y component of Velocity to some +ve value. And you will automatically observe a smooth jump.

What actually happens here, when you set the velocity’s Y to positive value, the player starts to rise up in space but since there is also some -ve acceleration, the velocity will also decrease, and at a particular height, velocity will become 0 and starts to drop down. The best part of this approach is that, it gives you a great feel of realistic gravity.

Note: (I am taking down left as (0,0) coordinate)