1
\$\begingroup\$

In my project I have a ball with a PhysicsMaterial where:

  • Dynamic Friction and Static Friction both are 0
  • Bounciness = 1
  • Friction Combine is set to Multiply
  • Bounce Combine is set to Maximum

This ball has a Rigidbody attached in which:

  • mass = 1
  • drag and angular drag both are 0
  • useGravity = true

In my scene there are some cubes which create a boundary for the ball to bounce inside. The ball bounces in a closed boundary. The problem is that over time the ball's maximum velocity keeps on increasing, and after some time it escapes the boundaries.

How can I prevent the velocity of this ball from exceeding a provided maxVelocity?

\$\endgroup\$
1
  • \$\begingroup\$ Presumably you considered caching the kinetic energy of the ball on start, and using a script to periodically adjust its velocity to not exceed that initial energy? \$\endgroup\$
    – DMGregory
    Oct 1, 2019 at 10:15

1 Answer 1

0
\$\begingroup\$

If the ball's high velocity is causing it to escape its boundaries you can improve high speed collision detection by changing the ball's rigidbody collision detection mode to "Continuous Dynamic". You can read about the details of collision modes here in the unity docs.

I'm not sure what the cause of the continuous acceleration is, I would guess either gravity, or bounciness unintentionally being calculated as >1.

Since there is no drag and collisions are perfectly elastic, there is no reduction in energy to offset the acceleration of gravity (other than gravity offsetting itself ie: as the ball bounces upwards, gravity pulls it downwards).

Alternatively one of the physics materials involved in the collision may be set to a bounce mode that is resulting in the bounciness of a collision exceeding one, thereby adding energy to the system with every bounce.

If investigating gravity and bounce don't lead to anything you may need to set an upper limit on the ball's speed, you can see some discussion about how to implement a max speed/terminal velocity here on the unity boards.

\$\endgroup\$

You must log in to answer this question.

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