Libgdx - How do I get the position of a fixture?

TL;DR How do I get the friggin’ position of a Fixture from a libgdx Contact object?


Contact col = cols.get(i);
Entity entA = (Entity)col.getFixtureA().getBody().getUserData();
Entity entB = (Entity)col.getFixtureB().getBody().getUserData();

These are the first lines in my collision-code, the rest of which is otherwise unimportant and trivial.
I want to place an explosion in the middle of the fixture hit on my ship, if it is a killing shot.
As you can see, I can get the exact fixtures colliding from the Contact object, and they both may or may not be a part of a large body with many fixtures (in this case bullets and ships), and I can get the body it belongs to.

Problem: How do I find the position, or even better the middle, of the fixtures in my Contact object?

I can put userdata into the fixtures, but since I use Aurelien’s BodyEditorLoader, it loads a bunch of fixtures, from which I get no information. They are just created. What I CAN get, is the childIndexNumber, which I presume is the index of this child in it’s parent Body’s fixtureList. So I canget get almost any information from anywhere…but not the position.

Solutions:

  • Hardcode every offset of every fixture into them after they’re loaded… (sucks)

Eh… probably you want to have [icode]Vector2 position = col.getFixtureA().getBody().getWorldCenter();[/icode], which returns you the middle of your entity in meters relative to the origin of the world (I think it even accounts the center of mass, if I didn’t mess up something…).

Yeah, that’s good. But I want to know the position of every particular fixture in a ship, which might have up to 8 fixtures.

Then you’d use [icode]contact.getFixtureA().getBody().getFixtureList();[/icode], no? This would provide you all the “neighboring” fixtures of your ship.

I guess there is no other way, and this way doesn’t seem like a hack to me :slight_smile:

Well, that doesn’t exactly give the positions of any of the fixtures, just a way, as you say, to find out which place in the Body’s array the current fixture has. So I guess I have to create a list of all the debris-positions manually, and put it in the UserData.

Oh well, onwards to vengeance!!