Page 1 of 2
Tile-based Collisions: getting stuck
Posted: Mon May 07, 2012 8:38 pm
by kcirbmab
I'm currently using Tiled with Advanced Tile Loader for maps for a simple platforming game. I'm using the default LOVE physics engine to create a body for each solid tile. The player object successfully collides with solid tiles and, for the most part, everything seems to be working well. The problem is that if the player object is at the exact position in between two adjacent, solid blocks, it will "trip" and fall over. If rotation is turn off, the player simply gets stuck and can't move forward unless you jump.
Is there a way to prevent this? Does HardonCollider have the same issues?
Here is the code used to create the bodies:
Code: Select all
for x=0, map.width do
for y=0, map.height do
if foreground.tileData(x,y) then
local ctile = {}
ctile.body = love.physics.newBody(world,x*16,y*16)
ctile.shape = love.physics.newRectangleShape(16,16)
ctile.fixture = love.physics.newFixture(ctile.body, ctile.shape)
end
end
end
I've also attached the love file.
Re: Tile-based Collisions: getting stuck
Posted: Mon May 07, 2012 8:51 pm
by Puzzlem00n
Okay, first of all, why use love.physics for a platform game? It's not meant for stuff like that. You're better off using Hardon Collider or your own collision code.
I quote the wiki:
love.physics is not lightweight, and not even remotely simple to use. It's a ten-ton hammer designed for heavy-lifting (er...hammer...lifting?).
If you are just trying to make a character jump around on blocks or the likes, then move along, nothing to see here.
Re: Tile-based Collisions: getting stuck
Posted: Mon May 07, 2012 10:48 pm
by kcirbmab
I've looked into HardonCollider but I've run into another issue. Since the map is tile based, each tile is it's own shape. When the player is touching two tiles at once, it gets pushed up to much and bounces. Is there any work around for this? The only way around it that I can find is to use Tiled objects that span multiple tiles for collisions, but it's a lot more time consuming to set up maps. Perhaps there's no way around it?
Re: Tile-based Collisions: getting stuck
Posted: Mon May 07, 2012 11:07 pm
by kikito
Doing it manually is possible, and the code can be actually very easy to understand; but writing it is a bit trickier than it might seem. I've been wanting to write an article on this, but I just lack the time right now.
In the meantime, if you feel adventurous, you might want to give a look at
this function. It should work provided 4 conditions:
- Your entities and tiles are all axis-aligned rectangles.
- Your entities rectangles are always smaller than your tiles.
- Your entities x,y coordinates point to the center of their "collision rectangle"
- Your entities don't move faster than 1 tile per frame
I've tried to make the code easy to understand and adapt, but I just can't explain everything right now. I hope it helps you in any case.
Re: Tile-based Collisions: getting stuck
Posted: Tue May 08, 2012 11:32 am
by Puzzlem00n
Alright, you know what, just for you I'm going to upload a .love of a platformer I made just for fun. It's very basic and has some flaws, but it works well enough for learning purposes. Tell me if you have any trouble understanding how it works.
Re: Tile-based Collisions: getting stuck
Posted: Tue May 08, 2012 12:06 pm
by Zeliarden
Yo!
Use a Circle instead of a Rectangle as your "feet". You can attach a several shapes and bodys to a fixture I think?
Re: Tile-based Collisions: getting stuck
Posted: Tue May 08, 2012 8:43 pm
by Puzzlem00n
Zeliarden wrote:Yo!
Use a Circle instead of a Rectangle as your "feet". You can attach a several shapes and bodys to a fixture I think?
We kind of just all agreed he should avoid the physics module, but yeah, I guess what you're saying may be true.
Re: Tile-based Collisions: getting stuck
Posted: Wed May 09, 2012 5:58 pm
by Zeliarden
We kind of just all agreed he should avoid the physics module, but yeah, I guess what you're saying may be true.
Why shouldnt he use the love.physics module? He already have the love.physics working.
Okay, first of all, why use love.physics for a platform game? It's not meant for stuff like that.
What about this then?
viewtopic.php?f=5&t=3794
You're better off using Hardon Collider or your own collision code.
I say love.physics is pretty easy to use. (maybe even easier than Hardon Collider or aleast at same difficulty)
I quote the wiki:
love.physics is not lightweight, and not even remotely simple to use. It's a ten-ton hammer designed for heavy-lifting (er...hammer...lifting?).
If you are just trying to make a character jump around on blocks or the likes, then move along, nothing to see here.
That "warning sign" should be removed or changed to something that dont scare off new lövers. (is it for an older ver.?)
Re: Tile-based Collisions: getting stuck
Posted: Wed May 09, 2012 8:59 pm
by Puzzlem00n
Zeliarden wrote:
I quote the wiki:
love.physics is not lightweight, and not even remotely simple to use. It's a ten-ton hammer designed for heavy-lifting (er...hammer...lifting?).
If you are just trying to make a character jump around on blocks or the likes, then move along, nothing to see here.
That "warning sign" should be removed or changed to something that dont scare off new lövers. (is it for an older ver.?)
No, it's not, it's there because of exactly why it says its there. It's not referring to the syntax, it's about the engine and how much unnecessary processing power (in this case) it takes to run, which has not changed. To be honest, the physics module should scare off new lövers because it's really not worth using unless you need heavy physics, and the run-of-the mill platformer doesn't need them.
Zeliarden wrote:
Okay, first of all, why use love.physics for a platform game? It's not meant for stuff like that.
What about this then?
viewtopic.php?f=5&t=3794
That's a different story. That is a game that requires heavy physics and has physics-based mechanics, which an SMB clone does not. (see Mari0.)
Zeliarden wrote:
You're better off using Hardon Collider or your own collision code.
I say love.physics is pretty easy to use. (maybe even easier than Hardon Collider or aleast at same difficulty)
It's not a matter of how easy it is, it's just that, as I said above, it takes a lot of unnecessary processing power that could be saved by making the same thing with a different method.
I'm not trying to start an argument here, I'm just explaining what I've said.
Re: Tile-based Collisions: getting stuck
Posted: Wed May 09, 2012 9:58 pm
by SudoCode
kikito wrote:Doing it manually is possible, and the code can be actually very easy to understand; but writing it is a bit trickier than it might seem. I've been wanting to write an article on this, but I just lack the time right now.
In the meantime, if you feel adventurous, you might want to give a look at
this function. It should work provided 4 conditions:
- Your entities and tiles are all axis-aligned rectangles.
- Your entities rectangles are always smaller than your tiles.
- Your entities x,y coordinates point to the center of their "collision rectangle"
- Your entities don't move faster than 1 tile per frame
I've tried to make the code easy to understand and adapt, but I just can't explain everything right now. I hope it helps you in any case.
Reading through that makes me want to go back and rewrite all my code in a neater fashion.