public class BulletScript : MonoBehaviour
{
private void OnCollisionEnter2D(Collision2D other)
{
if (other.gameObject.tag == “Player”)
{
Physics2D.IgnoreCollision(other.collider, GetComponent());
}
else if (other.gameObject.tag == “Enemy”)
{
Destroy(other.gameObject);
Destroy(gameObject);
}
else Destroy(gameObject);
}
}
This up here is my bullet script. Why when I shoot I can jump on or collide with the bullet for the first time? After that I can go trough it.
Thanks in advance!
Set your bullet collider3D as isTrigger and use OnTriggerEnter2D
instead of OnCollisionEnter2D
. That way, you can delete your
if (other.gameObject.tag == "Player")
{
Physics2D.IgnoreCollision(other.collider, GetComponent<Collider2D>());
}
Or even better use LayerCollisionMasks