Platform character shape

Hi all,

So I'm getting there slowly with Box2D. I'm writing a 2D platform game, and I want to mimic the physics of Sonic the Hedgehog for the main character (at least as a base). I'm having a couple of issues.

Firstly, because my game is made up of tiles, and I know that using a box for the character is a bad idea (from the FAQ) I've been using a sphere. However, this causes a problem because I need my character to be half as wide as it is tall. How can I overcome this? Is there a way to create an Ellipse rather than a sphere? What's the normal way for dealing with this? If I could make an ellipse, how do I prevent it from rolling over onto its side?

Secondly, while using a circle is working *most* of the time. I've noticed that sometimes the shape can become immovable when it collides with a static box. I'm using SetLinearVelocity (although I'm intending to change that to impulses). Could a circle being stuck against the side of a box be caused by my (mis)use of SetLinearVelocity or is there another known situation where a circle could become stuck to a box?
You can put two circles on a single body.

I don't know why your character is getting stuck. Can you reproduce the problem with some sample code? Try disabling continuous physics (see b2World). Try updating to the latest code in SVN.
I'll try to reproduce the problem later. I've just read in another thread that the SVN version has a b2LoopShape class. Would this be good choice to use for my character (if I programmatically generate the vertices for a capsule)?

Thanks for your help!

EDIT:

Here is a picture of the circle getting stuck:
Image

It can happen on any of the boxes along that vertical side, but it's always roughly in the same position relative to the box (e.g. about 1/3 down from the top of the box). When that happens my SetLinearVelocity calls do nothing and gravity does nothing as well, it's just stuck until I quit.

I'm hoping to combine a lot of the tiles into edge loops, perhaps that will make the problem go away. I also will be upgrading my code to the SVN version today - maybe that will fix it.
OK, this is interesting... so I updated Box2D to the version in svn (I had to edit some stuff to get it to compile.. my compiler doesn't have std::sqrtf, just plain sqrtf). Anyway, now the problem hasn't gone away, but now it freezes my whole application when it happens rather than just the simulation. It's as if it's stuck in an infinite loop somewhere. It happens in exactly the same situation, the bug looks the same, if I hadn't noticed that my log output had come to a standstill I wouldn't have noticed any difference from before.

EDIT:

If it helps, I sent a SIGINT to gdb, and got the following backtrace (e.g. this is where it's getting in some kind of loop)

Code:

(gdb) bt
#0  0x00007ffff591e5bf in ?? () from /lib/libc.so.6
#1  0x00007ffff591f354 in mcount () from /lib/libc.so.6
#2  0x0000000001d63410 in ?? ()
#3  0x0000000001d63410 in ?? ()
#4  0x00007fffffffdaf0 in ?? ()
#5  0x00007fffffffdaf0 in ?? ()
#6  0x0000000001d63410 in ?? ()
#7  0x0000000000483614 in b2CircleShape::RayCast (this=0x483942, output=0x7fffffffdad0, input=..., transform=..., childIndex=32767) at /home/luke/The Nova Project/nova/src/physics/Box2D/Collision/Shapes/b2CircleShape.cpp:82
#8  0x0000000000484550 in b2Min (a=..., b=...) at ../src/physics/Box2D/Common/b2Math.h:559
#9  0x000000000048f485 in b2AABB::Combine (this=0x7fffffffdae0, aabb1=..., aabb2=...) at ../src/physics/Box2D/Collision/b2Collision.h:197
#10 0x000000000048e652 in b2DynamicTree::InsertLeaf (this=0x1b55a28, leaf=91) at /home/luke/The Nova Project/nova/src/physics/Box2D/Collision/b2DynamicTree.cpp:197
#11 0x000000000048f164 in b2DynamicTree::Rebalance (this=0x1b55a28, iterations=4) at /home/luke/The Nova Project/nova/src/physics/Box2D/Collision/b2DynamicTree.cpp:376
#12 0x00000000004abf31 in b2BroadPhase::UpdatePairs<b2ContactManager> (this=0x1b55a28, callback=0x1b55a28) at ../src/physics/Box2D/Collision/b2BroadPhase.h:214
#13 0x00000000004ab53c in b2ContactManager::FindNewContacts (this=0x1b55a28) at /home/luke/The Nova Project/nova/src/physics/Box2D/Dynamics/b2ContactManager.cpp:170
#14 0x00000000004b0e92 in b2World::SolveTOI (this=0x1b3c788, step=...) at /home/luke/The Nova Project/nova/src/physics/Box2D/Dynamics/b2World.cpp:817
#15 0x00000000004b1043 in b2World::Step (this=0x1b3c788, dt=0.0166666675, velocityIterations=10, positionIterations=10) at /home/luke/The Nova Project/nova/src/physics/Box2D/Dynamics/b2World.cpp:867
#16 0x00000000004b497d in physics::Simulation2d::do_step (this=0x1b3c750, step=0.0166666675) at /home/luke/The Nova Project/nova/src/physics/simulation2d.cpp:16
It is hard to tell what is happening. I've never seen a circle get stuck on the side of a polygon before. Are you making any modifications inside a listener? Can you reproduce this in the testbed? Are you using gdb raw? I recommend a better debugger.

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