I’ve some test scene set up like this, once unity enter play-mode sphere 1 & 2 will start moving forward using the same velocity. Sphere 1 will bump into some cubes along the way. The outcome I expect is both spheres will always have the same z position value, which means no speed loss during the collision for sphere 1.
Rigidbody of both sphere setting are :
Mass = 1, Drag = 0, angular drag = 0, use gravity = false,is kinematic = false, Interpolate = Interpolate, Collision Detection = Continuous.
Physics material of both cubes and spheres are using :
Dynamic friction = 0,
Static friction = 0,
Bounciness = 0,
Friction Combine = Minimum,
Bounce Combine = Maximum.
I have been using following code to handle collision and velocity changes :
private void OnCollisionEnter(Collision other)
{
Debug.Log(body.velocity);
body.constraints = RigidbodyConstraints.FreezeRotation
| RigidbodyConstraints.FreezePositionY;
body.velocity = Vector3.forward * 5f + Vector3.left * 5f;
Debug.Log(body.velocity);
}
private void OnCollisionExit(Collision other)
{
body.constraints = RigidbodyConstraints.FreezeRotation
| RigidbodyConstraints.FreezePositionY
| RigidbodyConstraints.FreezePositionX;
Debug.Log(body.velocity);
}
According to the log message, the velocity of sphere 1 has been reduced most of the time when it collide with the cude in OnCollisionEnter().
As result, sphere 1’s Z position is incremetally behind sphere 2.
Is there something I been missing out or did I missunderstood how velocity of a rigidbody work?