Following along on the course, my spaceship would have its pitch and roll “snap” if moving all the way one way and then quickly reversing direction (see gif).
I was able to fix this by clamping the maximum change in pitch and roll per frame.
[SerializeField] float maxRotationalDelta = 4f;
private void ProcessRotation() {
float pitchDueToPosition = transform.localPosition.y * positionPitchFactor;
float pitchDueToMovement = yThrow * controlPitchFactor;
float targetPitch = pitchDueToPosition + pitchDueToMovement;
float yawDueToPosition = transform.localPosition.x * positionYawFactor;
float targetYaw = yawDueToPosition;
float rollDueToMovement = xThrow * controlRollFactor;
float targetRoll = rollDueToMovement;
//clamps pitch delta maximums per frame to prevent snapping
float pitchCurrent = transform.localEulerAngles.x;
float pitchDelta = Mathf.DeltaAngle(targetPitch, pitchCurrent);
float pitch = pitchCurrent - Mathf.Clamp(pitchDelta, -maxRotationalDelta, maxRotationalDelta);
//clamps roll delta maximums per frame to prevent snapping
float rollCurrent = transform.localEulerAngles.z;
float rollDelta = Mathf.DeltaAngle(targetRoll, rollCurrent);
float roll = rollCurrent - Mathf.Clamp(rollDelta, -maxRotationalDelta, maxRotationalDelta);
transform.localRotation = Quaternion.Euler(pitch, targetYaw, roll);
}