Rolling critters

I gave my pill bugs the circular hull they so richly deserved, so now they roll around when they happen to fall onto their back. Check it out:

For anyone reading this hoping to generate a half circle using Farseer (the C# port of Box2D), I’m pretty sure the current version is buggy. When I asked it to create an arc pi radians wide, I got something that looked like this:

Definitely not a full half circle. I want my money back.

See how it looks like they just chopped off the top 40 percent or so of a circle? Turns out that the Farseer code to create an arc looks like the following:

float stepSize = radians / sides;
for (int i = sides - 1; i > 0; i--)
{
    vertices.Add(new Vector2(radius * (float)Math.Cos(stepSize * i),
                                radius * (float)Math.Sin(stepSize * i)));
}
return vertices;

Given the behavior I was seeing, the loop conditions seemed very fishy to me, like they were chopping off the first and last point in the arc. I changed them to take in the whole range of the angle given, like so:

for (int i = sides; i >= 0; i--)

Sure enough, that gave me my half-circle:

Now that is a decent looking half circle

I went on to add the little guy’s feet to the physics model as well (not pictured), so this particular enemy is about as well-modeled as I can make him at the moment. It’s kind of interesting to see him collide with projectiles and get knocked around. Hopefully I manage to design some levels that can be shortcut by abusing this behavior.

Leave a Reply

Your email address will not be published. Required fields are marked *