So I create a body with a load of vertex points, via
But I've got my own engine that controls all of these objects via
Problem is, doing this for many objects seems to be a mild bit heavy. The engine has reference to all the vertices and how they update, but trying to just update those broke collision detection because of, I think, something not updating with it's AABB, but I'm not in any way sure.
Is there any way I can update a body's position and rotation directly, without breaking collisions?
Any help is appreciated and if you need any more info, just say. Thanks.
Code:
b2Def.fixture.shape = b2Def.polygon;
var len:int = poly.vertices.length();
var vertices:Vector.<Number> = new Vector.<Number>(len*2, true);
var i:int;
for(i = 0; i < len; i++)
{
vertices[(i * 2)] = poly.vertices[i].x / scale;
vertices[(i * 2) + 1] = poly.vertices[i].y / scale;
}
var fixtures:Vector.<b2PolygonShape> = b2PolygonShape.Decompose(vertices);
len = fixtures.length;
for(i = 0; i < len; i++)
{
b2Def.fixture.shape = fixtures[i];
addFixtureToBody(b);
fixtures[i].destroy();
}
var len:int = poly.vertices.length();
var vertices:Vector.<Number> = new Vector.<Number>(len*2, true);
var i:int;
for(i = 0; i < len; i++)
{
vertices[(i * 2)] = poly.vertices[i].x / scale;
vertices[(i * 2) + 1] = poly.vertices[i].y / scale;
}
var fixtures:Vector.<b2PolygonShape> = b2PolygonShape.Decompose(vertices);
len = fixtures.length;
for(i = 0; i < len; i++)
{
b2Def.fixture.shape = fixtures[i];
addFixtureToBody(b);
fixtures[i].destroy();
}
But I've got my own engine that controls all of these objects via
Code:
public function updateBody(id:String, x:Number, y:Number, rotation:Number=0):void
{
(bodies[id] as b2Body).SetTransform(new V2(x, y).divideN(PHYSICS_SCALE), rotation);
}
{
(bodies[id] as b2Body).SetTransform(new V2(x, y).divideN(PHYSICS_SCALE), rotation);
}
Problem is, doing this for many objects seems to be a mild bit heavy. The engine has reference to all the vertices and how they update, but trying to just update those broke collision detection because of, I think, something not updating with it's AABB, but I'm not in any way sure.
Is there any way I can update a body's position and rotation directly, without breaking collisions?
Any help is appreciated and if you need any more info, just say. Thanks.