Hi, I have set a rigibody gravity to true. I set useGravity = false when it collide with other box but the rigidbody won’t stop. I can see the value of use gravity is change to false from inspector window. So, how to stop a rigidbody from keep falling?
You need to put rigidbody first. Like:
rigidbody.useGravity = false;
yes, I have put it but still not working.
void OnTriggerEnter (Collider other) {
//some stuff here
rigidbody.useGravity = false;
}
The object still reacts to forces. It just won’t accelerate, giving your rigidbody the floating, gravity-less effect. To stop from moving you need to set it’s velocity to Vector3.zero.
Ok, it’s working now. It’s stop moving but the moving box stop a little bit inside the other box. How to solve it?
You could try going to Edit → Project Settings → Physics and changing the Min Penetration For Penalty value.
–Eric
Still the same.
It go to like stop at surface of 2 boxes now when I use this script: transform.Translate(0,(float)0.3,0);
but I think it not the solution because I put it location by 0.3 manually. Any idea?
translate it by normal of the collision multiplied by the the penetration distance.
Sorry, I’m not understand. Is there any function to get penetration distance?
No. There is really nothing you can do but guesstimate, or find another way to do this