In the unity physics system, It may be hard to get a perfect bouncing ball.
Bounciness is 1 and drags,frictions are all 0.
In my thought , it will be a perfect bouncing ball, but it isn’t.
It is getting more and more energy.
So, I want to know how to get a perfect bouncing ball in 3D.
In case,
Let me explain my program .
In the cube, there are 300 spheres. they collide with each other and cube.!
It would be better if you could explain to us what you mean by "perfect bouncing ball". Is a ball that doesn't lose energy when it bounces perfect? It doesn't sound realistic to me, but maybe that's what you are trying to achieve. So please, explain. Besides, if you are using physics, you have to think that gravity and other forces have an impact on your ball when bouncing. And you also need to have a look at the bounce combine property, which also plays a role when colliding with other elements. Again, tell us what you want to achieve and maybe someone can help you.
I’d be happy to be proved wrong but as far as I know Unity and/or nVidia don’t publish the equations uses for PhysX calculations, nor make anything like physic materials user extendable, so it is basically impossible to construct accurate physics systems based on precisely researched values. Unfortunately this seems to extend to edge cases like elastic collisions (zero energy loss). I’ve seen the same thing where full bounciness with zero friction and drag results in energy being added, and balls gaining rotational energy when they should be slowing down due to friction. I’m not sure if this is a floating point math issue, a bug, or a known limitation.
Fortunately elastic collisions with fixed surfaces are easy enough to calculate yourself. Forget Physic Materials and do something like this:
Don’t use Unity collision handling (not sure if this is possible when using OnCollisionEnter)
Use OnCollisionEnter or OnTriggerEnter to be alerted when a collision occurs
OnCollisionEnter: Calculate the average of the normals of the collision… OnTriggerEnter: use a Raycast to find the collision surface and get the normal
Use Vector3.Reflect to reflect velocity: “rigidbody.velocity = Vector3.Reflect(rigidbody.velocity, normal);”
For my game Stryker: First Person Football I had to use a hybrid custom + PhysX physics system to work around the limitations of the builtin Unity Physics, including modifying the dynamic friction based on the speed of the ball. It’s far from perfect but the result is fairly realistic.
You'd get a +1 from me, if you weren't advertising.
I found that it only bounces perfectly (reaches the exact same height each time it bounces) if the “Linear Drag” and “Angular Drag” properties are set to 0 and the “Collision Detection” property is set to “Discrete” on the Rigidbody (I am using a 2D Rigidbody).
The Physics material must have exactly 1 “Bounciness” and 0 “Friction”.
No, this is a perfect bounce, unless you want an impulse each bounce using acceleration makes the bounces higher, consistently over time.
void OnCollisionEnter ( Collision collision )
{
// Get the contact point's normal (opposite direction)
Vector3 collisionNormal = collision.contacts[0].normal;
// Apply force in the opposite direction of the collision normal
rb.AddForce(-collisionNormal * bounce, ForceMode.Acceleration);
}
It would be better if you could explain to us what you mean by "perfect bouncing ball". Is a ball that doesn't lose energy when it bounces perfect? It doesn't sound realistic to me, but maybe that's what you are trying to achieve. So please, explain. Besides, if you are using physics, you have to think that gravity and other forces have an impact on your ball when bouncing. And you also need to have a look at the bounce combine property, which also plays a role when colliding with other elements. Again, tell us what you want to achieve and maybe someone can help you.
– Andres-FernandezThank you Andres Fernandez. I will explain this more detail. http://en.wikipedia.org/wiki/Elastic_collision That is, There is no gravity and friction. And their Bounciness is 1.
– jinsung486This answer might be useful: http://answers.unity3d.com/answers/1086088/view.html
– toromano