I noticed that I was having a problem with quadratic drag at high velocities. If I give my objects a quadratic drag of 0.1 and speeds in the 1000's, then instead of coming to a halt, they fly away instantly.
I checked what was happening to the velocities over several updates:
So, it is oscillating from positive to negative, and growing. Since it was happening at high speeds only, I guessed it was related to quadratic drag. Looking at the code for quadratic drag, I think I found an error that is causing the drag to be hugely greater
than it should be.
From line 867 of Body.cs:
#region INLINE: Vector2.Multiply(ref linearVelocity, -_quadraticDragCoefficient * _speed, out _quadraticDrag);
_quadraticDrag.X = -QuadraticDragCoefficient * _speed * LinearVelocity.X;
_quadraticDrag.Y = -QuadraticDragCoefficient * _speed * LinearVelocity.Y;
As you can see, this section is meant to multiply the Coefficient by the speed, but it also multiplies by this extra factor of LinearVelocity.
I know that this factor was meant to cause the quadraticDrag to operate in opposition to the current velocity, so I tried changing both instances of LinearDrag.X/Y to Math.Sign(LinearVelocity.X/Y). This eliminated the problem.
Can someone verify that this is correct?