Falling
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
-
- Prole
- Posts: 32
- Joined: Sat Dec 21, 2013 5:16 pm
Falling
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!
- Attachments
-
- hells parkour.love
- (73.31 KiB) Downloaded 146 times
Re: Falling
Hi, the very basic equations for movement and gravity are these:
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.
Code: Select all
player.vy = player.vy + gravity * dt
player.x = player.x + player.vx * dt
player.y = player.y + player.vy * dt
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.
Check out my blog on gamedev
Re: Falling
this is how I learned gravity
Hope it helps you!
Hope it helps you!
- Attachments
-
- gravity.love
- (2.13 KiB) Downloaded 137 times
Who is online
Users browsing this forum: Ahrefs [Bot] and 10 guests