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

Vessel deformation after decoupling events due to autostruts #21

Closed
gotmachine opened this issue Mar 7, 2022 · 1 comment
Closed

Vessel deformation after decoupling events due to autostruts #21

gotmachine opened this issue Mar 7, 2022 · 1 comment
Labels
kspBug Identified KSP issue

Comments

@gotmachine
Copy link
Contributor

gotmachine commented Mar 7, 2022

Steps to reproduce :

  • In the editor :
    • Have a craft which is subject to some visible in-physics deformation
    • Setup autostruts in a way the ensure there are extra joints where deformation will happen
    • Have a decoupler anywhere
  • In the flight scene :
    • Engage the decoupler while there is some visible in physics deformation due to an external force (gravity...)
  • The deformation is now more "stable" (ie, the vessel doesn't return to the original state if the external force is removed)

Extra info :

Root cause :

This is caused by the Part.VesselModified() callback for GameEvents.onVesselWasModified calling Part.CycleAutoStrut() for all parts on the vessel.

Cycling autostruts mean all autostruts joints are immediately destroyed, and a coroutine is set to rebuild them in the next FixedUpdate.
This mean all autostruts joints on the vessel will be created anew, using the current in-physics part positions, essentially "freezing" any current deformation in place.

Note that GameEvents.onVesselWasModified is called by other things, meaning that issue can also happen in a variety of other cases : part destruction, docking/undocking, jettisoning fairings, breaking antennas/solar panels, and likely other cases from various mods.

Conclusion and fix

While this is a relatively minor issue (since the deformation is temporary and reversible), this might be a major root cause of the perceived quirkiness of autostruts. Autostruts joints essentially "freeze" the parts in a non-pristine position, and beside the vessel deformation issue, this mean autostrut joints are fighting against the regular joints, leading to more instability in the overall physic/rigidbody simulation. To some extent, it is also an aggravating factor for BG robotics drift (see #13) since robotics override the original part positions based on the current in-physics deformation.

The implemented fix runs just after the autostrut joint (re)creation logic and :

  • Alter the joint anchor to target the original pristine part position.
  • Add a rotation offset to the joint, compensating the difference between the part current in-physics rotation and the original pristine rotation.

Fix shortcomings

The patch doesn't handle the case of autostruts targeting BG robotic parts, as in that case the joint target is the moving rigidbody for which a pristine pos/rot doesn't exists. These autostruts are untouched and follow stock behavior.
The patch should be relatively safe from a modding ecosystem perspective, but it might fundamentally conflict with other robotic implementation such as USI Construction or Infernal Robotics, some testing is needed

Reproduction pics :

image

@gotmachine gotmachine added the kspBug Identified KSP issue label Mar 7, 2022
gotmachine added a commit that referenced this issue Mar 9, 2022
- New bugfix : AutoStrutDrift, see [issue #21](#21).
- New bugfix : PartStartStability, see [issue #9](#9).
- The FlightSceneLoadKraken patch is superseded by the PartStartStability patch, which is now disabled by default
@gotmachine
Copy link
Contributor Author

Fix implemented in 1.8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kspBug Identified KSP issue
Development

No branches or pull requests

1 participant