0 votes

I'm working on a project where you can split polygons with lines. Like cutting them in pieces.
I calculate the resulting polygon parts and child to a rigidbody2D and add a CollisionPolygon2D, and it kind of works but they have strange behavior. It looks like the polyogons have unbalanced mass, so they don't always fall to the ground correctly. If I push them they move and roll sort of ok, but when they land flat on the ground sometimes the tilt back up again and come to rest on one corner.

The CollisionPolygon2D shapes are correct, and the polygons do register physics collisions as expected. I read somewhere that it could be the center of mass that's off, but I don't know how to adjust that.

Looking for advice on what I can do to fix this!

Polygon resting on one corner, instead of falling over.

Another example of the shape coming to rest in an unbalanced position

Edit: images don't seem to work for some reason. The images just shows the polygon resting on a corner, instead of flat against the ground.

Godot version 3.2.3
in Engine by (19 points)

1 Answer

0 votes
Best answer

I figured out a solution.
It turns out the origin of the rigidbody is in one corner of the node, so to speak. That is, the rigidbody may have its origin at (0,0), and the collider will by default not be centered around the origin, but instead have one corner at the origin. This leads to the strange unbalanced center of mass.
So everything inside the rigidbody needs to be offset by half the width and height. E.g. if the collider is 200 wide and 100 high, it needs to be offset to the position (-100, -50). Doing that makes the physics works as expected.

by (19 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to webmaster@godotengine.org with your username.