Quantcast
Channel: Questions in topic: "ignorecollision"
Viewing all articles
Browse latest Browse all 148

Physics2D.IgnoreCollision() Not working the first time it collides.

$
0
0
I have a code on a projectile that is supposed to go through the gameObject tagged as "Hexagono" if it's transparency is lower that a certain value, so I'm using Physics2D.IgnoreCollision() but for some reason it never works the first time the projectile collides (It immediately bounces off). However because my projectile bounces, it does seem to work every other time it collides with the same object (It successfully goes through the object). private void OnCollisionEnter2D(Collision2D collision) { if (collision.gameObject.tag.Equals("Hexagono")) { if (collision.gameObject.GetComponent().material.color.a <= 0.4f) { Physics2D.IgnoreCollision(collision.gameObject.GetComponent(), GetComponent()); } }else{ Vector2 tweak = new Vector2(Random.Range(-1f, 1f), 0f); GetComponent().velocity += tweak; } }

Viewing all articles
Browse latest Browse all 148

Trending Articles