# GMS 2.3+Physics: Moment of Inertia

#### rytan451

##### Member
I'm designing a system involving numerous particles. I want to be able to set the moment of inertia of these particles. At first, I had considered using the function physics_mass_properties to set the moment of inertia. However, a closer look at the documentation indicates that the fourth parameter `inertia` is in fact linear inertia. Citation:

As for the inertia, this basically defines how resistant the instance is to changes in its direction and velocity, so a higher inertia makes it more resistant and a low inertia makes it less resistant (inertia and mass cannot be negative values!).
Since `inertia` controls the linear inertia of a physics object, how can I set the moment of inertia for a physics object?

As a side note, if `inertia` controls the linear inertia of a physics object, wouldn't that make `mass` redundant? Why, then, are `mass` and `inertia` parameters?

#### rytan451

##### Member
I've filed a ticket with the helpdesk, since I suspect that the manual was misleading. It appears that `physics_mass_properties` pretty much hooks into Box2D, creating a b2MassData struct, and using it to set the mass data of the physics body using b2Body::SetMassData. Thus, `inertia` would be the moment of inertia of the body.

#### Slow Fingers

##### Member
As a side note, if `inertia` controls the linear inertia of a physics object, wouldn't that make `mass` redundant?
No. Moment of inertia is also known as angular mass. The catch is how the mass is distributed is taken into account, as well as the axis around which it's rotating.

#### rytan451

##### Member
No. Moment of inertia is also known as angular mass. The catch is how the mass is distributed is taken into account, as well as the axis around which it's rotating.
That's exactly the point. If moment of inertia is angular mass, and `inertia` is linear inertia, then what do I use to set the moment of inertia?

Anyways, the bug has been confirmed, and my later conclusion that `inertia` is actually moment of inertia (rather than linear inertia) is correct. The manual will be updated to reflect this.

#### Slow Fingers

##### Member
That's exactly the point. If moment of inertia is angular mass, and `inertia` is linear inertia, then what do I use to set the moment of inertia?
Not quite sure I get your endgame, but you dont "set" the moment of inertia, it is defined by angular momentum/angular velocity.
Sorry I can't really help you on the GM side, I never use the physics system, I just remember college a little bit #### rytan451

##### Member
Not quite sure I get your endgame, but you dont "set" the moment of inertia, it is defined by angular momentum/angular velocity.
...

In the source code of box2D, on line 94 of the physics body definition, it sets mass, and on line 97, it sets the moment of inertia. I was looking for the appropriate function to set the latter variable through GML.

#### Slow Fingers

##### Member
...

In the source code of box2D, on line 94 of the physics body definition, it sets mass, and on line 97, it sets the moment of inertia. I was looking for the appropriate function to set the latter variable through GML.
GML:
``````    // Compute center of mass.
if (m_mass > 0.0f)
{
m_invMass = 1.0f / m_mass;
localCenter *= m_invMass;
}

if (m_I > 0.0f && (m_flags & e_fixedRotationFlag) == 0)
{
// Center the inertia about the center of mass.
m_I -= m_mass * b2Dot(localCenter, localCenter);
b2Assert(m_I > 0.0f);
m_invI = 1.0f / m_I;

}
else
{
m_I = 0.0f;
m_invI = 0.0f;
}``````
Not so sure it's possible to directly set the moment of inertia, as it's directly related to other parameters, as you can see. It depends of your center of mass.

#### rytan451

##### Member
Not so sure it's possible to directly set the moment of inertia, as it's directly related to other parameters, as you can see. It depends of your center of mass.
It's possible, through the b2Body::SetMassData method (line 351). At least, if the center of mass is at the origin of the object.