- Home /
minimum angular velocity?
Hi, I was trying to get an object to rotate in a random direction very very slowly. But I found that there seems to be a limit to how slow it can rotate because when i tried to get it to rotate at less than .02 units it seems to start rotating and stops. I have no angular drag on my rigidbody or gravity. This is my code:
float tumble=.01f;
void Start ()
{
GetComponent<Rigidbody>().angularVelocity = Random.insideUnitSphere * tumble;
}
Is there any way to get an object to rotate at a given speed without angularVelocity?
I cant really open up unity right now and recreate your problem but if i were you i would focus on what i did wrong rather then ways to bypass this issue, since it seems weird that a widespread commercial well tested physics engine will have such precision problems.
have you tried logging the current angular speed in each frame in the Update() function ?
does it drop in a linear pattern ? at once ? at random ? if you use higher speed does it persist ?
I would test all these things in a brand new project
Answer by Bunny83 · Jul 16, 2015 at 01:04 PM
Well, you are close to the default "Sleep Threshold" of "0.005". I'm not sure if it's translated 1:1 from angularVelocity but if it is it would mean when your "random point" has a radius less than 0.5 it will fall asleep since it moves too slow and is considered to not move at all.
For the physics system it's important to have such a threshold to ignore things ( Rigidbodies ) that do not move at the moment. If you set this threshold to 0.0, no Rigidbody will ever fall asleep. Depending on the amount of physics objects in your scene this might have a heavy impact on performance. You shouldn't lower the global Physics.sleepThreshold (which can be set in the project settings). Instead you can try to set Rigidbody.sleepThreshold to 0 (since you want an eternal motion for that object).
However keep in mind if objects can collide with that RB, it might loose energy. As alternative you can try setting angularVelocity each FixedUpdate to a constant value, or use Rigidbody.MoveRotation in FixedUpdate to rotate it "manually".