Search Unity

Question Large Angular Drag Causing Z-Axis Drifting

Discussion in 'Physics' started by lcompton, Nov 27, 2023.

  1. lcompton

    lcompton

    Joined:
    Mar 31, 2018
    Posts:
    102
    My game is set in space, so zero gravity is being simulated. My player movement is done via applying force and torque. I have a fairly high angular drag applied to the player Rigidbody (4 vs. the default 0.05). This makes turning more manageable by dampening the torque.

    My player gradually drifts along positive Z-axis. I just went through a round of debugging and discovered that the drift goes away if I set the angular drag to 0 or something small like the default 0.05. Larger values cause the drift.

    Why is this happening? Is there a way to prevent it? I'm not asking for a workaround, there are some things I've already thought of. I'm interested in understanding why the physics system is doing this and if there's a way to configure the physics system to prevent it.
     
  2. Edy

    Edy

    Joined:
    Jun 3, 2010
    Posts:
    2,507
    Without having a direct answer about the angular drag, I'd check how inertia is configured in the Rigidbody. If it's not configured explicitly then the physics engine will be computing the inertia out of the colliders associated to the rigidbody, which typically results in non-uniform inertia (= inertia rotation different than identity). A non-uniform inertia in Unity/PhysX might produce unexpected effects.

    So the first thing I'd try is configuring the inertia rotation to identity, either in the inspector (Unity 2022+) or from scripting in an initialization method. If the problem persists after that, then the PhysX drag implementation would be the cause of the issue. The only solution I can think of is then setting angular drag to 0 and implement the drag yourself. This shouldn't be difficult as it's just applying a torque opposing the angular velocity.
     
    lcompton likes this.
  3. lcompton

    lcompton

    Joined:
    Mar 31, 2018
    Posts:
    102
    Thanks for the suggestions. I tried setting the inertia rotation but that didn't help. I did find a workaround. I introduce a tiny amount of random torque once a second. That's enough to reset whatever is introducing the drift. I didn't mention before that the drift builds velocity over time, but rotating in any direction resets it.

     
    Edy likes this.