Ignore Physics Material For Certain Collision

Hello,

I have 2 certain objects that collide with each other. One of them has a bounce property to its Physic Material, but I do not want these two objects to bounce off of each other.

Is there a function similar to Physics.IgnoreCollision that can ignore the bounce property for the collision?

Thanks

@TzahiGames @Matberseris
This example uses a Trigger but the same should work in any collision event.
But if Iā€™m understanding the question, and there may be other ways to solve it but

[RequireComponent(typeof(Collider))]

[SerializeField]
float defaultBounceValue;

public GameObject otherCertainObject;

void Start()
{
    defaultBounceValue = GetComponent<Collider>().material.bounciness;
    //or
    defaultBounceValue = otherCertainObject.GetComponent<Collider>().material.bounciness;
}
    
void OnTriggerStay(Collider col)
{
    //Depending on how you have it set up
    if (col.gameObject.name == "Certain Object" || col.gameObject.tag == "Certain Object")
    {
        col.GetComponent<Collider>().material.bounciness = 0f; 
        //or
        gameObject.GetComponent<Collider>().material.bounciness = 0f;
    }
}

void OnTriggerExit(Collider col)
{
    GetComponent<Collider>().material.bounciness = defaultBounceValue;
}
1 Like

Maybe not the most elegant solution, but what I did in my game, which is a single screen 2d rocket league mini game, I doubled the walls and put bounce on one and put it on a layer only the ball can collide with using the Physics 2D Layer Collision Matrix. I put smoothing on the second wall and disable collision with the ball layer on that wall. Works really well in my situation, but probably not the best for larger games.