Hi, I'm developing a 2D platforming video game with JBox2D. I'd like my sprite to have a center of mass down towards the feet, so she keeps balanced even on slight slopes. I was delighted to learn that JBox2D supported compound shapes, and I decided to experiment with a shape like this:
So I tried doing this with the following code, taken right out of the CompoundShapes demo:
And what happens is:
http://www.youtube.com/watch_private?v=KMwX-eFer3E&sharing_token=d1vV3j91ZOEnBB7BP2amhQ
It seems like an issue with improper calculation of center of mass, but getLocalCenter returns the right center of mass - the same value returned in the CompoundShapes demo.
What's maddening is that the CompoundShapes demo works great, running from the same project linking with the same JBox2D code. In the demo I can change densities, rotations, positions, whatever - and it still works. I've tried paring my project down so the only object in the World is this body. And it still breaks in exactly the same way!
HELP!
NOTE: I am using JBox2D SVN, checked out a week or so ago.
Code:
_
| |
__| |__
-------
This would be two rectangles, one horizontally oriented and one vertically popping out from the top of the horizontal one. Also, the bottom one would have much more mass than the top one, maybe 10 or 100 times more.| |
__| |__
-------
So I tried doing this with the following code, taken right out of the CompoundShapes demo:
Code:
PolygonDef sd1 = new PolygonDef();
sd1.setAsBox(0.25f, 0.5f, new Vec2(0.0f, 0f), 0);
sd1.density = 0.1f;
PolygonDef sd2 = new PolygonDef();;
sd2.setAsBox(0.5f, 0.25f, new Vec2(0.0f, -1f), 0);
sd2.density = 200f;
myShapes.add(body.createShape(sd1));
myShapes.add(body.createShape(sd2));
body.setMassFromShapes();
sd1.setAsBox(0.25f, 0.5f, new Vec2(0.0f, 0f), 0);
sd1.density = 0.1f;
PolygonDef sd2 = new PolygonDef();;
sd2.setAsBox(0.5f, 0.25f, new Vec2(0.0f, -1f), 0);
sd2.density = 200f;
myShapes.add(body.createShape(sd1));
myShapes.add(body.createShape(sd2));
body.setMassFromShapes();
And what happens is:
http://www.youtube.com/watch_private?v=KMwX-eFer3E&sharing_token=d1vV3j91ZOEnBB7BP2amhQIt seems like an issue with improper calculation of center of mass, but getLocalCenter returns the right center of mass - the same value returned in the CompoundShapes demo.
What's maddening is that the CompoundShapes demo works great, running from the same project linking with the same JBox2D code. In the demo I can change densities, rotations, positions, whatever - and it still works. I've tried paring my project down so the only object in the World is this body. And it still breaks in exactly the same way!
HELP!
NOTE: I am using JBox2D SVN, checked out a week or so ago.