Fix catastrofic rotation after undocking from space station. #5422
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When ship docks with space station on autopilot it often generates pairs of big torque and force values that mostly cancel each other in normal flight. Problem starts with docking because when the flight state is changed to DOCKING which translates to m_isMoving==false for DynamicBody then the last unprocessed m_torque and m_force are stored. Those unconsumed torque and force values are later processed after undocking sequence completes and ship switches to FLYING state. This often results in catastrophic rotation + linear movement with ship just throwing forward thruster for few seconds. In many cases it is fatal. I have attached a savegame - those torque and force values are serialized. It can be used for reproducing the result - just load the save and press F5 to undock. You can also fly around the space station and dock couple of times - maybe with 3rd person view - to see if you can make the game store such values yourself.
So the fix is simple resetting torque, force, velocity and rotation when DynamicBody state is changed to m_isMoving==false.
I could not find a bug report for this thing.
The save game:
test.gz