5
\$\begingroup\$

I am building a 3D Pong clone and want to implement a frictionless bouncing ball.

These are the steps i took:

  1. Create a box in which the ball can bounce, consisting of standard cubic objects.
  2. Create a ball using a spherical object
  3. Add a Rigidbody to said ball (Mass: 1, Drag: 0, A.Drag: 0, no Gravity)
  4. Add a bouncy Physics Material to the balls Sphere Collider (D.Friction: 0, S.Friction: 0, Bounciness: 1, Fraction Combine: min, Bounce Combine: max)
  5. Add a script to the ball that adds force to the ball on start:

Script Snippet:

void Start() {
    this.getComponent<RigidBody>().addForce(0, 0, 100);
}

When i play the scene, the ball will fly towards the wall and then stop. If i change the added force to (0,0,101) it works as intended. If i lower the mass of the ball and use the old force (0,0,100) it also works. But it will always stop at the wall, if the added force is <= mass*100.

What am i missing?

\$\endgroup\$
5
  • \$\begingroup\$ How fast is the ball going? Could you be hitting the physics engine's mimimum velocity (under which it sets velocities to zero to avoid vibration) \$\endgroup\$ Nov 12 '15 at 21:34
  • \$\begingroup\$ That can't be the reason as it works properly with double the speed. \$\endgroup\$ Nov 12 '15 at 22:08
  • \$\begingroup\$ AddForce should be on the walls, not the ball. Then you'd use collision detection to add force on collision. \$\endgroup\$
    – SanSolo
    Nov 16 '15 at 13:04
  • \$\begingroup\$ What I mean is, right now, force is added to the ball only once. If walls add force, the ball will keep bouncing. \$\endgroup\$
    – SanSolo
    Nov 16 '15 at 13:10
  • \$\begingroup\$ I tried something like that, but I think it plays against the general physics engine. The vector on collision will already be 0 for the respective dimension, so i cant simply reflect and reapply a force. What I am doing atm is that i am keeping my ball at a velocity higher than the one that simply stops by multiplying the normalized velocity vector with a speed variable. But in a lot of situations the ball will collide with a wall in small angle (with a slow speed towards the respective wall) and the ball will "attach" to the axis the wall is standing parallel to. \$\endgroup\$ Nov 16 '15 at 20:34
1
\$\begingroup\$

A guy on my development team actually found the source of the problem:

Unity has an internal Bounce-Threshold. If the velocity towards one axis does not reach this Threshold the velocity will be set to 0. This is a nice feature for normal game physics, as bouncing objects will come to a rest faster, but you can't build a perfect bouncing ball without lowering the value.

You can find the Bounce Threshold in the Physics Manager ( Edit > Project Settings > Physics ).

\$\endgroup\$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .