- Home /
Bouncing objects and Energy loss
Hi
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 ...
If it's only in 2 dimensions, you could write your own physics engine. It's much easier to make a stable physics system in 2 dimensions than it is in 3, and you won't have to do all that clamping business.
Answer by Berenger · Jan 15, 2012 at 05:31 AM
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 :)
I knew there was a way to do it with out animation, this may help me later on I'm doing a game with allot of traps #potential
Answer by lijrobert · Jan 15, 2012 at 02:58 AM
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.
I'm in 2 dimensions (camera ortho, no gravity, every rigid body frozen on one axe etc). An animation is not really going well with the random aspect I'm looking for. Plus the player can add walls anywhere.
Your answer
Follow this Question
Related Questions
Bouncing Ball and Walls 1 Answer
Cant find options to change physic material to bouncy 2 Answers
How to make an infinite mass solid body 1 Answer
Reducing bounce on simple boxes 0 Answers
Can't set Bounce Threshold below .3 0 Answers