开发者

Box2D Flash engine problems with collision detection

开发者 https://www.devze.com 2023-04-01 12:17 出处:网络
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.

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.C开发者_运维百科reateShape(polyDef);


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);
0

精彩评论

暂无评论...
验证码 换一张
取 消