Physics calculations

Hi! Does anyone know how Unity manage the motion of a Rigidbody starting from a force/torque? I would like to make a boat moving following a mathematical approach to calculate the forces acting on the hull but I need to know how the motion equations are solved.

Hi, why not add a rigidbody to the boat and use the physics already there? Perhaps it’s just to adjust the friction and apply force in the right direction to make it move over the water surface plane like a boat.

That’s exactly what I want to do. Indeed, I added the rigidbody to the boat. I’ll try to explain better my problem. I need a force calculation based on physical equations, which I have, but I need to know if there’s consistency between the mathematical model by which I obtain the forces and Unity motion equation solving.
For example, the motion of a craft depends also on the off-diagonal terms of the tensor of inertia, but they cannot be found in the Rigidbody element. It seems to me that the tensor of inertia considers only the diagonal elements (it’s a Vector3 if I’m right), but i’d like to know if there are also the off-diagonal terms somewhere or, better, a complete matrix for masses and inertia for the 6DOFs.

I guess the Drag always works in the opposite direction to the movement, or applied force, and the friction along the surface it’s sliding over. The gravity, if used, apply force downwards, and the angularDrag dampens any rotation. If the material has bouncines, it will reflect of in the opposite direction when hitting walls.

And you can always get, and set the Vector3 values for Velocity, and anglularVelocity to the rigidbody to for example dampen sideway slip.

Most likely physics in Unity won’t work as you expect from the equations.

Inertia tensor is provided as two elements, Rigidbody.inertiaTensor and Rigidbody.inertiaTensorRotation. PhysX (the underlying 3D physics engine in Unity) calculates these elements unless they’re specified explicitly. What PhysX does is computing a standard 3x3 inertia matrix out of the colliders associated to the rigidbody. Then it converts such matrix into a Vector3 and a Quaternion that supposedly can be used to reconstruct the original 3x3 inertia matrix (we haven’t found how that can be done though).

PhysX uses these Vector3 and Quaternion in its dynamics calculations. This seems like a simplification of the rigid body dynamics, which might be somewhat faster than using the 3x3 matrix. The problem is that such simplification is so severe that inertia behaves way differently than expected:

  • Changing the inertia alone doesn’t change angular velocity. The classic example about a figure skater increasing his angular velocity decreasing his moment of inertia is not possible in Unity/PhysX.
  • Inertia is used to calculate the delta angular velocity only when an off-center force or torque is applied to the rigidbody.
  • Both angular velocity and axis of rotation remain constant if no forces or torques are applied to the rigidbody. In reality, non-diagonal inertia tensors imply both axis of rotation and angular velocities are changing while keeping the total momentum constant.

You can try basic examples in Unity, like a cube without gravity, apply forces and measure the results. You’re most welcome if you could bring some light that could result in better simulations!

Where on a boat would the rotating figure skater phenomenon apply, in a game simulation?

Very interesting. It seems that the problem is to understand how to link the 3x3 true inertia matrix and the Vector3/Quaternion associated.
Assuming that it could be possible, which could not be, it is possible to assign custom values to the Vector3 and Quaternion?

Even if you achieve that, still the engine doesn’t work realistically with non-diagonal inertia tensors.

Yes sure, you can write the values to the rigidbody’s inertiaTensor and inertiaTensorRotation properties.

Do you have a reference for that?

That’s standard Unity programming. Simply access the component and set the values:

If you want to know how PhysX converts a 3x3 inertia matrix to vector3 and quaternion, the answer to this question is a great reference:

Thank you!

It’s an example of the inertia in Unity not working as expected. In the case of a boat where the inertia tensor matrix is non-diagonal, the simulation in Unity will differ significantly from a correct rigid body simulation.