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
Answer by CORYB · Jun 07, 2018 at 06:49 PM
@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;
}
private void OnTriggerStay(Collider col)
{
if (col.gameObject.name == "Certain Object"
|| col.gameObject.tag == "Certain Object")
//Depending on how you have it set up
{
col.GetComponent<Collider>().material.bounciness = 0f;
//or
gameObject.GetComponent<Collider>().material.bounciness = 0f;
}
}
private void OnTriggerExit(Collider col)
{
GetComponent<Collider>().material.bounciness = defaultBounceValue;
}
Your answer
Follow this Question
Related Questions
How to calculate velocity after collision? 0 Answers
Why Does Bounciness Affects Rigidbody Velocity? (SOLVED) 0 Answers
How to use relativeVelocity to AddForce to the Rigidbody? 0 Answers
How do you detect a mouse button click on a Game Object? C# 2 Answers
Destroying GameObject on collision Problems (Begginer) 1 Answer