1
\$\begingroup\$

This is an odd one, that has me kind of stumped. If I execute the code:

void FixedUpdate()
{
    rigidbody.AddRelativeTorque(0, 1000, 0);
}

I get this:

enter image description here

Normal, expected behavior. The (car in this case) rotates fine around Y. But if I try and change the center of mass,

void Start()
{
    rigidbody.centerOfMass = new Vector3(0, -0.2, 0.9);
}
void FixedUpdate()
{
    rigidbody.AddRelativeTorque(0, 1000, 0);
}

test

The car spins on all 3 axis. AddTorque has the same problem. It is as if AddRelativeTorque/AddTorque are not accounting for the moved position of the center-of-mass. This was done in an empty Scene with the car floating at 0x 0y 0z.

\$\endgroup\$
4
  • 1
    \$\begingroup\$ I've seen issues in the past where updates to the physics engine's internal data don't get processed eagerly, but may be delayed, leading to unexpected behaviour in the meantime. Does using Physics.SyncTransforms or Rigidbody.ResetInertiaTensor change the results you get at all? \$\endgroup\$ – DMGregory Mar 3 '19 at 23:17
  • \$\begingroup\$ No combination of those two seems to change anything. AKA only Sync, only tensor, then sync+tensor and tensor+sync. \$\endgroup\$ – Sprocket Creations Mar 3 '19 at 23:28
  • \$\begingroup\$ The first thing I see is that the Local Center of Mass and the World Center of Mass are the same, but the position of the object isn't at zero. Or am I missing something about the World Center of Mass property? \$\endgroup\$ – Alex F Mar 4 '19 at 4:25
  • \$\begingroup\$ The object is at zero, but the car spins around the center of mass, so the transform changes, but not the world center of mass. \$\endgroup\$ – Sprocket Creations Mar 6 '19 at 0:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.