Page 1 of 1

Falling

Posted: Fri Jul 25, 2014 3:37 am
by thewifitree
I've had many problems with jumping and gravity. I've been working on this project for not too long and I am having problems with gravity, I believe it is in the loop but I can't figure it out :? Please help!

Re: Falling

Posted: Fri Jul 25, 2014 5:41 am
by micha
Hi, the very basic equations for movement and gravity are these:

Code: Select all

player.vy = player.vy + gravity * dt

player.x = player.x + player.vx * dt
player.y = player.y + player.vy * dt
x and y are the coordinates, vx and vy are the velocity in x and y-direction and gravity is gravity. Put this into the update.

In your code, I currently don't see any velocity vector.
I also observed that you move all the blocks in the background and not the player. I suggest doing it the other way around: Move the player, not the blocks. Then you need a camera module to follow the player. That may sound more complicated to implement, but is a more consistent and intuitive approach (for example doing collision detection with a resting player and moving blocks is a bit strange for my kind of thinking)

If you want to get started with gravity, I suggest that you first ignore collision detection. Check out the tutorial on exploding rabbits. That covers many aspects already.

Re: Falling

Posted: Mon Jul 28, 2014 7:04 am
by pielago
this is how I learned gravity
Hope it helps you!

Re: Falling

Posted: Thu Jul 31, 2014 4:40 pm
by thewifitree
Thank you so much!