- Home /
How to avoid objects bouncing and overlapping after collision?
Hello, guys!
I'am trying to avoid objects bouncing and overlapping after collision with obstacle. You can see the problem and objects configuration at the following video: http://www.youtube.com/watch?v=MrI0lo0fZ1I
All objects are rigidbodies and dragRigidBody script is used for dragging them. Moveable objects are non-kinematic and obstacles are kinematic.
Is there an easy way to solve this issue?
Thanks in advance, Sergei
hmm, after all your bumps I finally watched your video. It actually shows the problem well, and you show the inspector which is great. I would have to load that script and see how it works, and apparently mass is one of the factors that can be affecting the other non-kinematic rigidbodies (as well as imparting velocity by the collision on the other rigidbodies). Have you tried it without using a physics material, or even making your own physics material with no bounciness (create > Physic $$anonymous$$aterial)?
But in the meantime there is another script on the Unity Wiki that claims to be better than the Standard Asset script. Save your scene as a new scene with a different name, then try this script : http://wiki.unity3d.com/index.php?title=DragObject
You are right about the mass factor: it's increase leads to bounce reduce, but it also slows down drag speed, that makes user interaction uncomfortable.
I haven't tried to create new physic material, I'll try it with changing drag script and post results.
Thank's for your advices.
I had another couple of thoughts. This is only some untested theories, but maybe you can
1/ tell the other rigidbodies to Sleep :
2/ set the other rigidbodies velocity to zero :
Some Unity scripting References :
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody.Sleep.html
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-sleepVelocity.html
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-sleepAngularVelocity.html
http://docs.unity3d.com/Documentation/ScriptReference/Rigidbody-velocity.html
here are my ideas in a script form :
//on collision enter / stay / exit
function OnCollisionEnter( other : Collision )
{
// find the other rigidbody
var rBody : Rigidbody = other.collider.gameObject.GetComponent( Rigidbody );
// check there is a rigidbody
if ( rBody )
{
//Debug.Log( "other has Rigidbody" );
// check if the other rigidbody is$$anonymous$$inematic is false
if ( !rBody.is$$anonymous$$inematic )
{
//Debug.Log( "other Rigidbody is NOT $$anonymous$$inematic" );
// then tell it to sleep
//rBody.Sleep();
// or tell it that its velocity is now zero
rBody.velocity = Vector3.zero;
}
}
}
//on collision stay
function OnCollisionStay( other : Collision )
{
// find the other rigidbody
var rBody : Rigidbody = other.collider.gameObject.GetComponent( Rigidbody );
// check there is a rigidbody
if ( rBody )
{
//Debug.Log( "other has Rigidbody" );
// check if the other rigidbody is$$anonymous$$inematic is false
if ( !rBody.is$$anonymous$$inematic )
{
//Debug.Log( "other Rigidbody is NOT $$anonymous$$inematic" );
// then tell it to sleep
rBody.Sleep();
// or tell it that its velocity is now zero
//rBody.velocity = Vector3.zero;
}
}
}
//on collision exit
function OnCollisionExit( other : Collision )
{
// find the other rigidbody
var rBody : Rigidbody = other.collider.gameObject.GetComponent( Rigidbody );
// check there is a rigidbody
if ( rBody )
{
//Debug.Log( "other has Rigidbody" );
// check if the other rigidbody is$$anonymous$$inematic is false
if ( !rBody.is$$anonymous$$inematic )
{
//Debug.Log( "other Rigidbody is NOT $$anonymous$$inematic" );
// then tell it to Wake Up !
rBody.WakeUp();
}
}
}
Your answer
Follow this Question
Related Questions
Question on Vector3.Reflect() 2 Answers
C# GameObject is not detecting collision with Character Controller 2 Answers
Concave rotation Collision problem 3 Answers
C# Check Physics.Raycast Once 0 Answers
Destroy On Collision 4 Answers