- Home /
Change bounciness at runtime
A ball projectile is hitting bottles. Bottles move along a downward path using physics.
The projectile has a rigidbody with physic material in its sphere collider, with bounciness of 0. A bottle has a rigidbody with physic material in its collider, with bounciness of 0.
Bottles have different colors. Projectiles too. The idea is hitting bottles of the same color. No problem with the PhysX engine when projectile and bottle have the same color, it works as expected. The force of the projectile throws the bottle away. But when the projectile hits a bottle with different color, I want to the ball projectile to bounce; and the bottle to continue its way untouched.
Problems? A lot. - I tried to change the relative masses at OnCollisionEnter() expecting the bullet to rebound. Not working. - I tried to use Physics.IgnoreCollision(collision.collider, collider); at OnCollisionEnter(). Too late. - Changing the material for the bullet to make it bounciness.
I think what I need is to disable the physics for the bottle a bit before the collision, compare the colors and decide how to continue: - if same color, use physics. - if not, stop a bit the bottle physics, repel the projectile (how by the way?) and then continue the bottle physics.
Any idea? Anyone had a similar problem?
Answer by oasisunknown · Jun 07, 2014 at 10:44 PM
these objects sound like rigidbodies but with out your code its hard to give you any advice.
that being said here is what my guess would be.
Do a check when the ball enters the collider and check its color at that point verse that bottle just how you have been doing it.
if the colors match don't do anything because you said this part works already.
if the colors don't match then just give the ball an additional AddForce to give it a big push in the direction you want it to go.
I would not worry about how bouncy the object is. just give it an additional force and it will look like its bouncing away
but again if we can see your code we can give you more specific help.
Thanks, Oasis.
As I noted at the question, projectiles and bottles are rigidbodies. I need them to have real physics, except when hit and the color deter$$anonymous$$es what happens.
I've tried AddForce for the projectile at OnCollisionEnter(), that's O$$anonymous$$, no problem. Let's considered it solved.
But I can't keep the bottles from falling, when at OnCollisionEnter() it looks like it's too late to handle this. I tried changing masses, bounciness, Physics.IgnoreCollision. The bottle is already impacted.
Setting Is$$anonymous$$inematics = true for the bottle, stops the bottle from moving along a downward path using physics. I need this movement.
So, what I need is some way to avoid the collision for the bottle when colors are different.