Impact

This forum is read only and just serves as an archive. If you have any questions, please post them on github.com/phoboslab/impact

1 decade ago by AustinP

I'm trying to add shapes to a physics body at runtime as a result of some player action. I can add the new shape and that works fine, but I cant seem to set the new shapes position relative to an existing shape or really set the position at all. The new shapes are just getting stacked on top of each other.
Suggestions?

1 decade ago by dominic

I believe you have to manipulate the shape's vertices "by hand". See this blog post and the documentation.

I.e. something like this might do (untested):
var shape = new b2.PolygonDef();
shape.SetAsBox( 20 * b2.SCALE, 20 * b2.SCALE );
		
var moveX = 10, moveY = 20; // new relative position
for( var i = 0; i < shape.vertices.length; i++ ) {
	shape.vertices[i].x += moveX * b2.SCALE;
	shape.vertices[i].y += moveY * b2.SCALE;
}

1 decade ago by AustinP

That did it, Thanks for the help. Impact is a great engine.
Page 1 of 1
« first « previous next › last »