34880

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.

Answer1:

Yes.

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

<img src="https://i.stack.imgur.com/93nDx.png" alt="enter image description here">

Answer2:

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.

Recommend

  • Back and forth movement using Rigidbody2D movePosition
  • Lerp color based on distance between 2 objects
  • Changing scenes with StartCoroutine or Application.LoadLevel
  • Keep SKNodes from applying force to each other
  • Can't flip direction of ball without messing up gravity
  • Load scene with param variable Unity
  • Unity Disorted Audio
  • Java UDP Server, concurrent clients
  • Should I use folds in Turtle or Foldl packages?
  • faster way for calling audio element to play in html5
  • What is the best way to store a threaded message list/tree in SQL?
  • Sha-1 hash fixed point
  • Else if statements not running through all possibilities
  • Is there a way two make two trigger gameObjects collide?
  • Is SPLFileObject atomic?
  • Are there size limits to PHP array keys? What are the limits in general for PHP arrays? [duplicate]
  • How to implement collision detection on nodes which are in StackPane (in JavaFX)?
  • mysql utf8mb4_unicode_ci cause unique key collision
  • Different objects collide
  • Why are XML namespaces HTTP addresses?
  • 2D bouncing formula doesn't work properly
  • AndEngine: Handling collisions with TMX Objects
  • Angular dynamic component loading
  • How to create a discrete normal distribution in R?
  • Drop variable in panel data in R conditional based on a defined number of consecutive observations
  • How to deal with xxx~HEAD after git merge?
  • How to realize with WinForms in C# something like an image with map areas in a homepage (at hooverin
  • UUID into unsigned int
  • Determine if a mesh is inside another mesh in threejs
  • Is there a greater chance to collide when comparing GUIDs based on a hash vs \"Guid.NewGuid()?
  • Git Merge Adds New File Instead of Conflict Markers - CONFLICT (rename/add)
  • Get MP3 ID3 meta data and song duration using AudioStreamer
  • C++ std::set comparator
  • Prolog Query - Trying to understand how this result happens
  • Efficiently getting XML into Elasticsearch
  • Does the failbit effect the call ignore on cin?
  • Error in GGally: Error in unit(tic_pos.c, “mm”) : 'x' and 'units' must have leng
  • Negating Regex PO BOX
  • Tap to record like in vine using javacv
  • How solve “Qt: Untested Windows version 10.0 detected!”