RigidBody's moment of inertia: how is it calculated/edited?

DanHugoDanHugo Posts: 2Member

How does Godot 3 determine the moment of inertia of a RigidBody? For example, does it take the collision shapes, assume the rigid body's mass is uniformly distributed throughout their volume, and compute the tensor accordingly, or does it use some other method?

Can I edit the tensor programmatically? Eg like how Unity exposes inertiaTensor and inertiaTensorRotation to override the values computed from colliders.

(Forgive me if this is covered elsewhere, but I was unable to find anything else in the docs, and I'm only new to Godot. The only thing the documentation has to say about rotation is "float angular_damp - Damps RigidBody’s rotational forces." That's it. Not a very physical description.)

Tagged:

Tags :

Answers

  • TwistedTwiglegTwistedTwigleg Posts: 1,043Admin
    Answer ✓

    Good question! Unfortunately, I have no idea on the answer. This might be best asked on the Facebook/Reddit/IRC/Discord and/or the Github repository where there are more C++ Godot developers who are more experienced with Godot’s core and may be able to answer your question.

    I know that Andrea Catania on Github wrote the bindings to allow Godot to use Bullet Physics, so he’d probably have the best chance of knowing.

    As for editing the tensor programmatically, I do not think it is possible. Perhaps with the _intergrate_forces function you could, but as far as I know with Bullet Physics the _intergrate_forces function is not working for RigidBody nodes.

  • DanHugoDanHugo Posts: 2Member
    edited December 2018

    Thanks for the response, TwistedTwigleg. :) I'll check out the Reddit. Just curious... when you say "_intergrate_forces function is not working for RigidBody nodes", what do you mean exactly?

    I eventually worked out that the moment of inertia properties -- named inverse_inertia and principal_inertia_axes -- are available in PhysicsDirectBodyState class, meaning it's accessible via the rigidbody's state variable in _integrate_forces (and probably not arbitrarily settable). Experimentally, center_of_mass appears to simply be the translation of the RigidBody, unaffected by collider geometry. Meanwhile, I can't quite work out how moment of inertia is determined, as it's possible to build objects from a pair of box colliders and get some unexpected values. For a single box collider, inverse_inertia and principal_inertia_axes vary with scale, but not with translation of collider away from the centre_of_mass... this seems like a contradiction to me, but maybe I need to read up on the physics a bit. :)

  • TwistedTwiglegTwistedTwigleg Posts: 1,043Admin

    @DanHugo said:
    Thanks for the response, TwistedTwigleg. :) I'll check out the Reddit. Just curious... when you say "_intergrate_forces function is not working for RigidBody nodes", what do you mean exactly?

    Sorry, I should have explained better.

    Last I knew, and maybe it is fixed now, the _intergrate_forces function does not work with the Bullet physics engine Godot uses. It still works fine with the old custom Godot physics engine, but apparently there was some issues getting it to work with Bullet and ultimately I think it was disabled.

    I could be wrong though, it’s been awhile since I’ve read anything about it so maybe it’s working now.

    I eventually worked out that the moment of inertia properties -- named inverse_inertia and principal_inertia_axes -- are available in PhysicsDirectBodyState class, meaning it's accessible via the rigidbody's state variable in _integrate_forces (and probably not arbitrarily settable). Experimentally, center_of_mass appears to simply be the translation of the RigidBody, unaffected by collider geometry. Meanwhile, I can't quite work out how moment of inertia is determined, as it's possible to build objects from a pair of box colliders and get some unexpected values. For a single box collider, inverse_inertia and principal_inertia_axes vary with scale, but not with translation of collider away from the centre_of_mass... this seems like a contradiction to me, but maybe I need to read up on the physics a bit. :)

    Sounds complicated, but I’ve never been particularly good with physics. I wish you the best of luck figuring everything out.

  • wombatstampedewombatstampede Posts: 65Member

    Hi DanHugo.
    As far as I know from Godot 2.x the inertia was determined from the Collision Shapes as far as they were standard shapes (collision shapes based on imported/custom meshes were ignored). And be careful with scaling. I think inertia calculations ignored the effects of (uneven) scaling in 2.x and the physics/collision engine had problems with scaled collision shapes.

    I am currently in the process of porting my boating game to 3.x and expecting mucho mayhem. ;-)

Sign In or Register to comment.