Hey everybody, I am currently working on a game and the need to have curves in the game has come up. After a couple hours of research and work, I managed to parse a JSON object into a b2Shape using the SetAsVector method. However, whenever I have a dynamic body collide with the body, the dynamic body just slows to a crawl and starts moving through the static body. This behavior does not happen with basic shapes such as Box's and Circles. I've attached the swf of an example of my predicament, and a link of it here http://www.fastswf.com/SkyDFec
Below is my code for parsing the JSON non-rectangle polygons
Any ideas on what could be causing the weird collisions?
Below is my code for parsing the JSON non-rectangle polygons
Code: Select all
for (var k:int = 0; k < JSONObject.layers.length; k++)
{
var pointVector:Vector.<b2Vec2> = new Vector.<b2Vec2>();
for (var i:int = 0; i < JSONObject.layers[k].objects.length; i++)
{
var shape:Object = JSONObject.layers[0].objects[i];
if (shape.polygon != undefined)
{
var shapeSprite:Shape = new Shape();
shapeSprite.graphics.lineStyle(1, 0x000000);
for (var j:int = 0; j < shape.polygon.length; j++)
{
pointVector.push(new b2Vec2(shape.polygon[j].x / 30, shape.polygon[j].y / 30 ));
shapeSprite.graphics.lineTo(shape.polygon[j].x, shape.polygon[j].y );
}
var shape1:b2PolygonShape = new b2PolygonShape()
var bodyDef:b2BodyDef
bodyDef = new b2BodyDef();
bodyDef.type = b2Body.b2_staticBody
bodyDef.position.Set(shape.x / 30, shape.y / 30)
shape1.SetAsVector(pointVector);
var fixtureDef:b2FixtureDef = new b2FixtureDef();
fixtureDef.shape = shape1;
fixtureDef.density = 0
fixtureDef.restitution = 1;
fixtureDef.friction = .5;
fixtureDef.shape = shape1
bodyDef.userData = shapeSprite;
newChild.push(bodyDef.userData);
var body:b2Body = Level.gameWorld.CreateBody(bodyDef);
body.CreateFixture(fixtureDef);
}
}
}
Any ideas on what could be causing the weird collisions?