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.
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).
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;
}
}