Ignore Physics Material For Certain Collision
Asked Answered
S

2

0

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

So answered 16/10, 2023 at 7:19 Comment(0)
S
1

@Huppah @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;
}
Sportsman answered 16/10, 2023 at 7:18 Comment(1)

Not thtat i know of, but you can split the text into words, and then set a limit of how many characters can go into a line, count how many character the words have and based on the limit dived them into the lines.

Pneumectomy
K
0

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.

Kuster answered 15/10, 2023 at 21:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.