Calling the physics simulation from C#

Trying to understand if Physics.Simulate() can fix my problem – I’m trying to implement a friction on some ConfigurableJoints I have in a project. Basically, the joint has all the normal restrictions plus a “friction force” which subtracts a fixed magnitude of angular velocity (and the corresponding linear velocity based on the offset of centerOfMass to joint connection) in the opposite direction of current movement.

The problem lies in making sure this friction is subtracted from the final velocities AFTER all other forces are applied in the various FixedUpdates (joint connection forces, external “explosions” from other objects in the scene, etc.) as well as the automatic unity forces (gravity, collisions). There’s several limitations:

  1. There’s no PostDragAndCollisionsUpdate, or even a LateFixedUpdate for that matter (I guess you could do script ordering but I’m trying to avoid it).

  2. You cannot grab the net velocity added to a rigid body so even if I hack a LateFixedUpdate there’s no way to get what the final velocity will be (not to mention gravity, drag, and collisions have not yet been applied).

Looking at this thread and testing on my own I discovered the order of operations to be

  • Call FixedUpdate() for all objects.
  • Apply the net velocity from all received AddForce/AddTorque calls
  • Apply drag and angular drag
  • Apply collision forces

So my question is, how many of these steps are still hidden inside Physics.Simulate()? It sounds like FixedUpdate calls are still outside (and I imagine collisions are stuck inside) but what about drag and angularDrag? If I adjust the execution order for a CustomSimulationScript to be last can I create a pool of my joint objects and grab their final velocities somehow, apply my own drag formula (the friction), and then call Physics.Simulate()?

If not, would it be that difficult to expose the necessary information on Rigidbodies? Right now I’m simply acting on the final velocities from last frame and reverse engineering the required angularDrag and drag. It works okay-ish until there’s a significant change in velocity and weirdness ensues.

My conclusion at this point is that it’s impossible to get this working clean. Please show me how I’m wrong (: