sleepVelocity is broken?

If I understand it right, sleepVelocity will force freeze/sleep a rigidbody when its velocity is below the set value?

I created a gameobject->sphere, added a rigidbody to it and the script below.
Then I bounce with a player controlled ball gainst it,with such high sleep value it should fall back to sleep right away no?
Instead it very slowly comes to a stop.

function Awake()
{
	rigidbody.sleepVelocity = 100;
	rigidbody.sleepAngularVelocity = 100;
}



function Update()
{
	print(rigidbody.velocity.magnitude);
}

I want my player controlled object to come to sleep if it is moving to slow, so it doesn’t keep rolling forever on slightly uneven terrain but as the sleepvelocity value was not having any effect I was afraid adding a force of 0 also prevented the rigidbody to go to sleep. So I tried above above test setup with also no effect.

So do I understand the use of rigidbody.sleepVelocity wrong, am I doing something wrong or is it broken?

I have a feeling it’s terribly noobish, but I have to echo BlueStrike’s question.

It doesn’t seem to matter in the slightest whether I set Physics.sleepVelocity to 0.2 or 500.2.

I’m checking the rigidbody’s sleepVelocity at the time I set it to motion, and it reflects what I set it to in the Physics class. I don’t modify the rb in any way after I put it into motion.

What am I missing here?

I’m still befuddled by this.

The documentation speaks about cases when the rigidbody will wake up, and I’ve gone over each to check that none of these are creating problems for me:

another rigidbody collides with the sleeping rigidbody

No. At least not when the rb slows down. I print stuff out with each collision, so I’m certain on this point.

another rigidbody connected through a joint is moving.

No joints or otherwise attached gameobjects (none with RBs anyhow).

when modifying a property of the rigidbody

I access them on every frame, like here:

void FixedUpdate()
    {
        //Limit speed
        Vector3 velocity = rb.velocity;
        if (velocity.sqrMagnitude > maxBallSpeedSqr)
        {
            print("Clamping ball speed!");
            rb.velocity = velocity.normalized * maxBallSpeed;
        }
    }

… but this conditional only rarely passes.
I’m certain as can be, that I don’t actually modify anything about the ball otherwise.

when adding forces.

Certainly not.

The threshold for angular velocity is also set insanely high, so it can’t be waiting for that either.

I’m fairly sure there is no events I can catch for when a RB is awakened or put to sleep, but maybe I missed something here?

Do you have any suggestion for how I can track this down?

Thanks for your time!

I’m giving up on understanding why this doesn’t work for me, and will try to stop them ‘manually’ (as in, write my own code to do it).

I have one question in that regard: What exactly is this value you set with Physics.sleepVelocity ?

Is it the magnitude of the rigidbody’s velocity?

grumblebrokenforumgrumble

Double posting, generally slow and poor searches, and now new posts that doesn’t actually bumb the thread :frowning:

try this script, attach it to GameObject with rigidbody and fall it down, it work well for me.
140 blue balls with this script fall down and sleep after several collides.

I see no difference with your script. My Unity3d is 3.5.2f2

using UnityEngine;
using System.Collections;

public class RigidInTime : MonoBehaviour {
    public float mass = 200f;
    float sleepSpeed = 1f;

    void Start()
    {
        if (rigidbody == null)
        {
            gameObject.AddComponent<Rigidbody>();
            rigidbody.mass = mass;
        }
        Collider coll = gameObject.GetComponent<Collider>();
        if (coll != null)
            coll.isTrigger = false;
        rigidbody.sleepVelocity = sleepSpeed;
        rigidbody.sleepAngularVelocity = sleepSpeed;
    }
}

If you want the object to go to sleep below a certain speed, why not just tell it to?

public float sleepSpeed = 5; // m/s

void FixedUpdate() {
   if (object.rigidbody.velocity.magnitude < sleepSpeed)
      object.rigidbody.Sleep();
}

Manually stopping it is easy.

public float stopThreshold = 5; // m/s

void FixedUpdate() {
   if (object.rigidbody.velocity.magnitude < stopThreshold)
      object.rigidbody.velocity = Vector3.zero;
}

Hello all, check your Drag values on rigidbody, if they == 0 rigid newer go to slip after collide with other rigid.