CodeLook12
CodeLook12

Reputation: 29

Is there a way two make two trigger gameObjects collide?

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.

Upvotes: 3

Views: 8499

Answers (2)

CodeLook12
CodeLook12

Reputation: 29

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.

Upvotes: 0

axwcode
axwcode

Reputation: 7824

Yes.

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

enter image description here

Upvotes: 4

Related Questions