Game Development Community

Max Angular Velocity?

by Chase Webb · in Torque 2D Beginner · 04/14/2013 (5:48 am) · 1 replies

Just curious, but is there a way to set a maximum Angular Velocity on an object? I'm playing with some weird Point Force objects and some of them start spinning insanely when they get hit.

#1
04/14/2013 (7:37 am)
There are a couple of ways to handle it, but not an explicit setting for max velocity that I know of. Do you want your objects to be able to spin indefinitely, or slow down and stop? If you want them to stop, you can use setAngularDamping. That will make them slow down and stop spinning. Setting the value sufficiently high should keep them from spinning too wildly, I think.

The other option is to enable the update callback when they're hit, and put something like this in it:

function object::onUpdate( %this )
{
   %objVelocity = %this.getAngularVelocity();
   %objAbsVelocity = mAbs( %objVelocity );
   %velocityLimit = 50;
   if( %objAbsVelocity > %velocityLimit )
   {
      %this.setAngularVelocity( ( %objVelocity / %objAbsVelocity ) * %velocityLimit );
   }
}

What that code does is set the angular velocity to the limit if it's current value exceeds that limit. It also accounts for direction.

There's probably a more elegant way of handling this that someone else can suggest, but that should get you headed towards the solution you need.