Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a dampening torque when the angularDrag field is set #3787

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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