- Home /
,Trouble with Physics.IgnoreColliion
I am trying to have an object not collide with objects with the same tag as it. I do not want to use layers as I have ran into some issues with them and would like to avoid them. The OnCOllisionEnter() is being called, as shown by the Debug.Log(), but fore some reason the IgnoreCollision() doesn't work. Here is the simplest reproducible code: public class BulletCollision : MonoBehaviour { // Start is called before the first frame update void OnCollisionEnter(Collision collision) { Debug.Log(collision.gameObject.name); if (collision.gameObject.tag == gameObject.tag) { Physics.IgnoreCollision(collision.collider, GetComponent()); } } } Any help would be appreciated.,I want an object to not collide with objects that have its same tag, but I do not want to use layers, as I have ran into some issues with them. OnCollisionEnter() is called, as shown by my Debug.Log, but the collision still takes place. Here is the smallest reproducible code:
public class BulletCollision : MonoBehaviour
{
// Start is called before the first frame update
void OnCollisionEnter(Collision collision)
{
Debug.Log(collision.gameObject.name);
if (collision.gameObject.tag == gameObject.tag)
{
Physics.IgnoreCollision(collision.collider, GetComponent<Collider>());
}
}
}
Any help would be appreciated.
Your answer
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Picked up objects passes through objects 2 Answers
Help with destroying objects on collision 2 Answers
Object change direction after collide with controller 2 Answers