I've been developing a platformer and have come across a problem. If the player jumps from the top platform to the bottom he goes right through it but if he jumps onto it from the ground, he stays on it. I don't know what's going on.
Controls:
Arrow keys to move right/left
Spacebar to jump.
Hold lshift to run.
Also, I am using love 0.8.0
I'll appreciate any help, thank you in advance
Platform Collision problems
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
Platform Collision problems
- Attachments
-
- Platformer.love
- (1.78 KiB) Downloaded 65 times
My itch.io page is:
http://roggie.itch.io/
Twitter:
https://twitter.com/RoggieGaming
Website:
http://roggiegaming.comxa.com/
Blog:
http://urnet.net78.net/RoggieGaming
http://roggie.itch.io/
Twitter:
https://twitter.com/RoggieGaming
Website:
http://roggiegaming.comxa.com/
Blog:
http://urnet.net78.net/RoggieGaming
Re: Platform Collision problems
Hi,
the problem is in the AABB-collision-check. It should be this:
you had an additional "+ player.h" in there.
The next thing you should to is refine the collision resolution: If a collision occurs, then the player should not be set back to the previous position, but exactly onto the ground/platform. For that you need to know the direction in which the player moves: If he moves down and a collision occurs, then the player must be moved up onto the platform. If he moves up, then he must be moved down.
Besides that, you should move these two lines, from the love.draw to the love.load:
Otherwise two platforms are added each frame, which makes the table larger and larger over time.
the problem is in the AABB-collision-check. It should be this:
Code: Select all
if player.y + player.h > v.y and player.y < v.y + v.h and player.x + player.w > v.x and player.x < v.x + v.w then
The next thing you should to is refine the collision resolution: If a collision occurs, then the player should not be set back to the previous position, but exactly onto the ground/platform. For that you need to know the direction in which the player moves: If he moves down and a collision occurs, then the player must be moved up onto the platform. If he moves up, then he must be moved down.
Besides that, you should move these two lines, from the love.draw to the love.load:
Code: Select all
addplatform(0,love.graphics.getHeight() - 100,100,10)
addplatform(100,love.graphics.getHeight() - 180,100,10)
Check out my blog on gamedev
Re: Platform Collision problems
Thank you, the code works perfectly and I like your advice when you said:micha wrote:Hi,
the problem is in the AABB-collision-check. It should be this:you had an additional "+ player.h" in there.Code: Select all
if player.y + player.h > v.y and player.y < v.y + v.h and player.x + player.w > v.x and player.x < v.x + v.w then
The next thing you should to is refine the collision resolution: If a collision occurs, then the player should not be set back to the previous position, but exactly onto the ground/platform. For that you need to know the direction in which the player moves: If he moves down and a collision occurs, then the player must be moved up onto the platform. If he moves up, then he must be moved down.
Besides that, you should move these two lines, from the love.draw to the love.load:Otherwise two platforms are added each frame, which makes the table larger and larger over time.Code: Select all
addplatform(0,love.graphics.getHeight() - 100,100,10) addplatform(100,love.graphics.getHeight() - 180,100,10)
Looking back, that would have been a smart thing to do when i started coding the game.Besides that, you should move these two lines, from the love.draw to the love.load:Otherwise two platforms are added each frame, which makes the table larger and larger over time.Code: Select all
addplatform(0,love.graphics.getHeight() - 100,100,10) addplatform(100,love.graphics.getHeight() - 180,100,10)
My itch.io page is:
http://roggie.itch.io/
Twitter:
https://twitter.com/RoggieGaming
Website:
http://roggiegaming.comxa.com/
Blog:
http://urnet.net78.net/RoggieGaming
http://roggie.itch.io/
Twitter:
https://twitter.com/RoggieGaming
Website:
http://roggiegaming.comxa.com/
Blog:
http://urnet.net78.net/RoggieGaming
Who is online
Users browsing this forum: Bing [Bot], Semrush [Bot] and 4 guests