2
votes

This is for a 2D game.

I have a Player who can shoot trigger projectiles(with a trigger collider) and Enemies that can do the same. When a Player projectile collides with the Enemy, stuff happens and vice versa. However, when the Player projectile and the Enemy projectiles collide, they just ignore collision, go through each other, and nothing happens. They also have a Rigidbody2D with continuous collision detection.

Is there a way to make it so something happens when these two gameObjects with trigger colliders touch?

Here's what I've got for the Enemy projectile script:

void OnTriggerEnter2D( Collider2D other ){
    if (other.gameObject.name == "Ground"){ 
        Destroy (gameObject);
    } 
    else if (other.gameObject.name == "Player"){
        other.gameObject.GetComponent<RControlScript>().RHealth = other.gameObject.GetComponent<RControlScript>().RHealth - damage;
        Instantiate(transformInto, gameObject.transform.position, gameObject.transform.rotation);
        Destroy (gameObject);
    } 
    else if(other.gameObject.name == "Shot"){
        Destroy (gameObject);
    }
}

"Shot" being the name of the Player projectile being the gameObject not colliding with the Enemy projectile.

2

2 Answers

3
votes

Yes.

Here is a graph that tells you what collides with what in Unity3d.

enter image description here

0
votes

Ok, turns out two trigger colliders do in fact collide. My problem was that the projectiles instantiated were clones, therefore its name = "Shot(clone)". Had to change that in order to make things happen.