- Home /
How to get a perfect bouncing ball.
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.
Thank 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.
The example above is about bouncing between atoms. Those physics are different then 'normal' physics. The physics Engine works with other variables like gravity e.d. So, in other words you have to play with other variables to get your 'perfect' bouncing behavior.
This answer might be useful: http://answers.unity3d.com/answers/1086088/view.html
Answer by chesterhilly · May 08, 2015 at 06:14 PM
I know this sounds sad, but I spent about five mins trying to figure out how close you can get to perfect bounces with the physic material.
Create a physic material
Set the bounce combine to maximum
Change bouciness to 0.9699999 exact
I don't know if its much different to that but I put a background behind it and I saw it reach the same point.
A lot of months late but I think this was the best answer. It worked amazingly.
Answer by dakmau · Aug 29, 2016 at 09:30 AM
SOLVED
I had the same issue and resolved it without any code. My bouncing object was gaining kinetic energy with each bounce.
The issue was that the collision detection property was set to discrete.
Go into the rigidbody component and set the collision detection to continuous. That's it.
This worked for me. I had the exact same problem and this solved it. I had a paddle, and a ball with gravity 1, and bounciness 1. When it hit my collider on the paddle, it would bounce, but get extra energy each time.
Changed collision detection on Rigidbody of ball to continuous, and it fixed it. I have no idea why it works.
Documentation says:
Collision Detection How collisions with other objects are detected. Discrete A collision is registered only if the object’s collider is in contact with another during a physics update. Continuous A collision is registered if the object’s collider appears to have contacted another between updates.
Don't see why that made a difference?
At a guess: continuous collision may resolve the collision at the effective time of impact, whilst discrete collision resolves at the frame time where objects are already overlapping. The temporal inaccuracy of the discrete collision calculation could then potentially add energy to the system.
Answer by Huacanacha · Jun 30, 2014 at 04:25 AM
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.
You're right, I'll remove the link but leave the game name as it's potentially relevant to the discussion.
can you please give an example piece of code showing how did you do that? I am not getting the correct values of normal when I tried to do this.
Answer by thejaswip · Mar 22, 2016 at 01:48 PM
void OnCollisionEnter(Collision collision) {
rigidbody.velocity = new Vector3 (collision.relativeVelocity.x, collision.relativeVelocity.y);
}
Answer by Muffio · Jun 25, 2018 at 11:22 AM
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".
Your answer
Follow this Question
Related Questions
how the ball bounces of equal in angles? 1 Answer
Ball bounce angle 1 Answer
Object with rigidbody bounces after hit. 0 Answers
Enemy bouncing physics 0 Answers
Unity2D Collision is bugged 0 Answers