Set body angle to zero without moving vertices

Let us know if you have a nice R.U.B.E script to share!
Post Reply
iforce2d
Site Admin
Posts: 861
Joined: Sat Dec 22, 2012 7:20 pm

Set body angle to zero without moving vertices

Post by iforce2d »

Sometimes it's necessary to set the angle of a body to zero, but leave all the vertices of the body in their current positions. This script will do that for all selected bodies:

Code: Select all

vec2 originalCursorPosition = getCursor();

body[] bs = sb();
for (uint i = 0; i < bs.length; i++) {
	body b = bs[i];
	setCursor( b.pos );
	fixture[] fs = b.getFixtures();
	for (uint k = 0; k < fs.length; k++) {
		fixture f = fs[k];
		rotate( f.getVertices(), 0, b.getAngle() );
	}
	b.setAngle( 0 );
}

setCursor( originalCursorPosition );
Post Reply