Hi,
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:
{X:1600 Y:1600}
{X:4436.657 Y:4436.657}
{X:41966.29 Y:41966.29}
{X:4109227 Y:4109227}
{X:3.979607E+10 Y:3.979607E+10}
{X:3.732888E+18 Y:3.732888E+18}
{X:3.284388E+34 Y:3.284388E+34}
{X:Infinity Y:Infinity}
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;
#endregion
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?
