Emerick
Emerick

Reputation: 120

Box2D Flash engine problems with collision detection

I've seen this type of problem before, but didn't knew what is the solution. I've added this triangle to a b2Body Object(the body variable below) and the collision detection isn't working for it. The shapes just go through each other, I can't post the entire code cause it's quite large.

     polyDef.vertexCount = 3;
     polyDef.vertices[0].Set( 1, 2);
     polyDef.vertices[1].Set(1, 1);
     polyDef.vertices[2].Set(-9, 1);
     body.CreateShape(polyDef);

Upvotes: 0

Views: 694

Answers (1)

JiminP
JiminP

Reputation: 2142

The problem was the order of vertices.

Like Allan said, in Box2D, vertices should be in clockwise order, so it looks like that (1,2), (1,1), (-9,1) is in correct order.

However, since the y coordinate is upside down, that order is actually in CCW.

Therefore, the order should be changed like this.

polyDef.vertexCount = 3;
polyDef.vertices[0].Set( 1, 2);
polyDef.vertices[1].Set(-9, 1);
polyDef.vertices[2].Set(1, 1);
body.CreateShape(polyDef);

Upvotes: 1

Related Questions