0 votes

Hi,

Say I have a sphere mesh and I want to add collision object to it, so it can roll on the ground. The center of mass is always in the middle.

How can I change this and make my sphere heavier on one side, so when no other forces are applied, it will roll, so that the heavy part is touching the ground and resist further rolling a little bit?

in Engine by (136 points)

2 Answers

+1 vote
Best answer

You can't properly define it. By default the center of mass is at the origin of the body, regardless of shapes it contains.
For now, you have to offset your collision shapes in such a way that the origin of the body matches the position you want.

I posted an issue earlier to have the ability to change not only that, but also inertia tensor: https://github.com/godotengine/godot/issues/28062

by (27,595 points)
selected by

So if i make a rigid body with (0,0,0) coordinates, and then make a sphere with radius of 1, move it up by 1 and create a matching collision object, I should have a sphere with the center of mass located on its lowest point, right?

The position of the rigidbody itself doesnt matter, but the position of the collision shapes relatively to the rigidbody does the trick. So yeah if you create a sphere as a child and give it a local position of (0, 1, 0), its center of mass should be at the bottom.

OK, so for objects that don't have to dynamically shift their center of mass and can have it defined this way by hand, this is actually pretty good solution. Thanks!

0 votes

Mine is a more of a rudimental idea but you could use a local Position2D to mark the center of mass , you could set it the center and use it as a vector to where apply impulses or forces, and then move the Position2D to where you want it to be by script

by (57 points)

True, but shifting mesh and collision object relative to body is much simpler and doesn't require any scripts. Or are there any benefits of this solution, that I miss?

i thought you wanted to change the center of mass while in runtime
it's just another way to do that, not better, not worse, but surely rudimental Hahah :)

Well, I didn't tried it yet, but in theory if I would move mesh and collision relative to body at runtime via a script and make a counter-move for the body (in opposite vector), this should change center of mass while object would visibly stay in the same spot :)

I'm not an expert of balls , but i think your solution should work :=)

I thought about that solution too but it boils down to "teleporting collision shapes", which I had a lot of trouble with in the past, with bodies falling through ground or jumping around. It really should not be that complicated to change center of mass and inertia tensor, it's litterally a few variables somewhere in Bullet Rigidbody :p (we could even think about having the engine compute them automatically, provided the density of each shape!)

teleporting with physics objects is always a problem
It would be cool to make a feature request about that
in the meanwhile we could code such a function in the game itself, maybe as a singleton
i would need to revise some classic physics anyway Hahah

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.