var slantFixtureDef = new b2FixtureDef; slantFixtureDef.density = 1.0; slantFixtureDef.friction = 0.5; slantFixtureDef.restitution = 0.2; slantFixtureDef.shape = new b2PolygonShape; slantFixtureDef.shape.SetAsBox(10, 1);
What I really wanted was to use vertices for this shape so that I could rotate it how I wanted.
var points = [ {x: 0, y: 0}, {x: 0, y: 0.5}, {x: 5, y: 0.5}, {x: 5, y: 0} ]; var vecs = []; points.forEach(function(e, i, arr) { var vec = new b2Vec2(e.x, e.y); vecs[i] = vec; }); slantFixtureDef.shape.SetAsArray(vecs, vecs.length);
But creating a shape like this caused the problem of dynamic bodies not bouncing off this static body. The issue turned out to be that the vertices were specified in the wrong order. Box2dWeb requires you to specify the vertices in clockwise order even though the C++ version requires counter-clockwise order.
var points = [ {x: 0, y: 0}, {x: 5, y: 0}, {x: 5, y: 0.5}, {x: 0, y: 0.5} ];
Simple as that!
No comments:
Post a Comment