Is there a way to have a bunch of objects, let’s say balls, randomly launched in a closed area, bouncing forever with a constant speed? (I am trying to achieve that)
Everything in the scene has the same physic material, with no friction and bounciness = 1.The balls don’t have any drags.
I’ve noticed two things. First, when two balls collide, they cancel eachother’s energy when I want them to bounce and keep the same speed. Secondly, When the direction of a ball is almost parallel to the wall it’s heading for, the ball will stick to the wall forever.
Is there a way to get that behaviour only by a proper set up of the physic ? If it have to be by a trick in a script, so be it, but it seems dirty …
Problem solved, kinda. For those interested :
I am doing a mix of physic for collision detection, and simple movement (pos = pos + dir * speed, when collission you do dir = Vector3.Reflect( dir, normal ) and it’s ok )
The tricky parts :
Collide with the walls. The balls are kinematic, so the collision with walls is raised only if a non-kinematic rigidbody is awaken by the kinematic ball. Easy, give the walls a rigidbody with all constrains frozen.
Collide with other balls. Sweet Jesus, all the balls are kinematic, they won’t raise OnCollisionEnter event between each others ! Don’t panic. Create an empty gameObject child of the ball, with a rigidbody (no gravity, no drag, not kinematic), a sphere collider, then set one layer for the ball and a different one for the child. Edit->ProjectSettings-Physic, make sure the ball layer don’t collide with the child one. Then create a script for the child which send a message upwards when a collision occurs. Done
The only way I can think of doing some of the things your saying is by animating the balls, but there may be any easier way. Maybe with the wall problem you could make the wall a trigger and it activate a animation that makes the ball drop.