Clamping Angular and Linear Velocities

Topics: Developer Forum, User Forum
Nov 24, 2008 at 9:36 PM
Is there an easy way to clamp the angular and linear velocities for the entire physics engine? I seem to be running into NaN problems with the Angular velocities when I have some strong forces and collisions happen.
Nov 26, 2008 at 9:16 AM
Edited Nov 26, 2008 at 9:20 AM
Hi seiggy, I had exactly the same problems when I tried to drag an object with a FixedLinearSpring applied through static objects. I fixed the problem by changing:

// File: Dynamics\Body.cs
public class Body : IDisposable
{
    // ...
    public void ApplyDrag()
    {
        // ...
        _rotationalDrag = AngularVelocity * AngularVelocity * Math.Sign(AngularVelocity);
        _rotationalDrag *= -RotationalDragCoefficient;

        ApplyTorque(_rotationalDrag);
    }
    // ...
}

to

// File: Dynamics\Body.cs
public class Body : IDisposable
{
    // ...
    public void ApplyDrag()
    {
        // ...
        _rotationalDrag = AngularVelocity * AngularVelocity * Math.Sign(AngularVelocity);
        _rotationalDrag *= -RotationalDragCoefficient;

         // Added code
         if (Math.Abs(_rotationalDrag)>Math.Abs(AngularVelocity))
             _rotationalDrag = -AngularVelocity;

        ApplyTorque(_rotationalDrag);
    }
    // ...
}

The NaN problem with AngularVelocity doesn't happen any more this way, but I'm not sure if this is really a correct bugfix. The problem seems to be that the _rotationalDrag is "exploding" if AngularVelocity exceeds a specific value (depending on RotationalDragCoefficient). For me this really seems to be a bug in the engine.

greets sunDiver

PS: Although good work guys, I really enjoy using the engine :)
Mar 6, 2009 at 7:40 AM
I still get a NaN error even with this. :(  It happens when I have a spinning object collide with another object tied to the ground with a fixedlinearspring.  Anyone have any ideas? 

Fantastic engine btw!