Skip to content

Commit

Permalink
Merge pull request #3787 from pleroy/3697
Browse files Browse the repository at this point in the history
Add a dampening torque when the angularDrag field is set
  • Loading branch information
pleroy authored Oct 30, 2023
2 parents 2c97e7e + a5e7c9e commit e3a9d42
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions ksp_plugin_adapter/ksp_plugin_adapter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1701,6 +1701,25 @@ private void JaiFailliAttendre() {
part.CoPOffset)
});
}

// KSP sets |part.rb.angularDrag| and lets Unity/PhysX compute a
// dampening torque. However, it doesn't tell us about it so we end
// up with uncontrolled oscillations. Therefore, we must create that
// torque out of thin air here. Note that in FAR
// |part.rb.angularDrag| is 0 and we are properly given the torque
// through |Part.AddTorque| so this code has no effect. See #3697 and
// https://documentation.help/NVIDIA-PhysX-SDK-Guide/RigidDynamics.html#damping.
var drag_torque = -part.rb.angularDrag * part.rb.angularVelocity;
if (drag_torque != UnityEngine.Vector3.zero) {
if (part_id_to_intrinsic_torque_.ContainsKey(
physical_parent.flightID)) {
part_id_to_intrinsic_torque_[physical_parent.flightID] +=
drag_torque;
} else {
part_id_to_intrinsic_torque_.Add(physical_parent.flightID,
drag_torque);
}
}
}
}
}
Expand Down

0 comments on commit e3a9d42

Please sign in to comment.