This should be a quick question, with hopefully a quick answer. :) I am using box2d for a side scroller project I'm doing. All's going good, thanks for asking. :D Anyways, my character needed to differently sized boxes used for bounding. I thought it would be as simple as adding a new fixture to the body, but it didn't work. It crashes and I get this:
java: ./Box2D/Collision/b2Distance.h:103: const b2Vec2& b2DistanceProxy::GetVertex(int32) const: Assertion `0 <= index && index < m_count' failed.
I have no idea what that means. Here is the code I use to create the body and fixtures:
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DynamicBody;
bodyDef.position.set(level.character.position);
Body body = b2world.createBody(bodyDef);
level.character.body = body;
PolygonShape polygonShapeHead = new PolygonShape();
origin.x = level.character.circleBoundOrigin.x * 2.0f;
origin.y = level.character.circleBoundOrigin.y * 3.0f;
polygonShapeHead.setAsBox(level.character.circleBoundOrigin.x,
level.character.circleBoundOrigin.y, origin, 0);
FixtureDef fixtureDefHead = new FixtureDef();
fixtureDefHead.shape = polygonShapeHead;
fixtureDefHead.friction = level.character.friction.x;
body.createFixture(fixtureDefHead);
polygonShapeHead.dispose();
PolygonShape polygonShapeBod = new PolygonShape();
origin = level.character.rectBoundOrigin;
polygonShapeHead.setAsBox(level.character.rectBoundOrigin.x,
level.character.rectBoundOrigin.y, origin, 0);
FixtureDef fixtureDefBod = new FixtureDef();
fixtureDefBod.shape = polygonShapeBod;
fixtureDefBod.friction = level.character.friction.x;
body.createFixture(fixtureDefBod);
polygonShapeBod.dispose();
As far as I know, I'm doing everything properly. So why is it not working? Why does it crash? I'm using fixturedef. Could that possibly be the problem. Thanks!
setAsBox()does set the vertices incorrect? Like width=5, height=0. or width=-2, height=3? - noone