Rows of Blocks making character stick

I have created a platform game (non-scrolling) that is based around a grid of tiles. The problem I'm having is that when the character is moving along, every so often the character gets stuck on one of the tiles (I assume it's something to do with it sticking up a tiny bit). The problem is that when I print the Y position, they all show the same number.

I do convert all my pixels into meters by dividing by 20.0 and I turn them back by multiplying by 20.0 but I still get this problem.

Any ideas?
Hi Tom,

I can only guess that there's a snag caused by either a small gap between blocks or that the blocks are somehow not level in terms of position or height. One possible solution would be to use a circle shape instead of a rectangle shape to represent your player.
Hi,

Thanks for the response. I'll try a circle and see if that works!
Thanks for the suggestion, changing the player to a circle worked.

Unfortunately, in my game the player has to be able to push things around like square-shaped crates. These also get stuck at some points so I would prefer to fix this problem rather than make a workaround.
Two theoretical suggestions from me:

Cut off the corners of the boxes, it might help them slide over the bumps. Instead of using the simple SetAsBox, you'd have to draw your own 8 sided polygon.

Instead of making each tile a box, combine groups of tiles into larger rectangles. This can be a bit tricky if you're suppose to be able to destroy tiles, but it shouldn't be too tricky to figure out a conversion algorithm if they're static.

Hope it helps! Cheers
I am trying to create a box as you said, but this doesn't seem to be working, any ideas?

The shape is b2PolygonShape and the 0.01 is the amount I am wanting to create the little triangular cuts. Size is just a float with an average size of 1.5 in length.

Code:
    shape->m_vertexCount = 8;
    shape->m_vertices[0] = b2Vec2(0.01, 0.00);              // TopLeft (Top)
    shape->m_vertices[1] = b2Vec2(size - 0.01, 0);          // TopRight (Top)
    shape->m_vertices[2] = b2Vec2(size, 0.01);              // TopRight (Right)
    shape->m_vertices[3] = b2Vec2(size, size - 0.01);       // BottomRight (Right)
    shape->m_vertices[4] = b2Vec2(size - 0.01, size);       // BottomRight (Bottom)
    shape->m_vertices[5] = b2Vec2(0.01, size);              // BottomLeft (Bottom)
    shape->m_vertices[6] = b2Vec2(0, size - 0.01);          // BottomLeft (Left)
    shape->m_vertices[7] = b2Vec2(0, 0.01);                 // TopLeft (Left)
Oh that's not how you do it. What you're doing there is massive out of bounds memory corruption! Yay!
You should only ever access the m_vertices when you just edit it's contents. Never add to it that way!

You're supposed to use the b2PolygonShape::Set method to allocate memory for it, and you do it like this:

Code:
b2Vec2 vertices[8] = { b2Vec2(0.01, 0.00),
                                b2Vec2(size - 0.01, 0),
                                b2Vec2(size, 0.01),
                                b2Vec2(size, size - 0.01) ,
                                b2Vec2(size - 0.01, size),
                                b2Vec2(0.01, size),
                                b2Vec2(0, size - 0.01),
                                b2Vec2(0, 0.01)
                               }
shape->Set( &vertices, 8 );
Oh, thank you!

Unfortunately, my player still gets stuck. I am currently adding a "debug draw" mode that will draw all the collision boundries, that might make things clearer.
I have created the debug drawing mode and all the tiles do now have a small cut in the corners but this problem still happens.

About grouping many tiles together, I don't think this would be possible because many of the tiles are likely to move around.

I will keep working on the problem and any other ideas would be much appreciated...
The plan is to make this smooth for edge chains and loops. Currently it works okay.

Original thread: https://box2d.org/forum/viewtopic.php?t=6691