space shooter explosions

Hi,

I can’t get my explosions to work. When the bolt hits the asteroid they bounce off each other but do not explode and are gone from the game only after they leave the game area. The same when the player collides with the asteroid, they bounce off each other.
I followed the tutorial exactly and everything else is working just fine, however, when the asteroid was added, in tutorial it was gone in play mode and this was fixed by adding
if (other.tag == "Bounbry") { return; }

For me, it did nothing because the asteroid was not gone in the play mode anyway.

My code for the collision is the same as in tutorial (unless someone else can spot the difference)

public class DestroyByContact : MonoBehaviour {

	public GameObject explosion;
	public GameObject playerExplosion;

	void OnTriggrEnter(Collider other){
		if (other.tag == "Bounbry") 
		{
			return;
		}
	
		Instantiate(explosion, transform.position, transform.rotation);

		if (other.tag == "Player") {
			Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
		}

		Destroy (other.gameObject);
		Destroy (gameObject);
}
}

i think You should use like this…

void OnTriggrEnter(Collider other)
{
         if (other.tag == "Boundry") 
         {
           Instantiate(explosion, transform.position, transform.rotation);
         } 
         if (other.tag == "Player") 
        {
             Instantiate(playerExplosion, other.transform.position, other.transform.rotation);
         }
 
         Destroy (other.gameObject);
         Destroy (gameObject);
 }

Thank you for your reply. Is there a difference? Except spelling of ‘Boundry’ of course. I did fix the spelling and copied the code, but still no change.

I added score count as well and it does nothing. Nothing in void OnTriggerEnter(Collider other) is executed. The objects don’t get destroyed, the explosion animation is not triggered and now the score counting is also not executed.

Do I have to call the function somewhere?

Hi @ebucna .

**1. Check Spelling of the ‘Tag’ in the Editor. It’s “Boundary” not ‘Boundry’. You’re missing ‘a’ between ‘d & r’. **

See Image
98703-tag-info.jpg

2. Now make correction in your script too. If it still doesn’t work then below is another script.

Here’s the script. Read with your beady eyes. From head to toe.

void OnTriggerEnter(Collider other)
	{
           //You can check with CompareTag.
          /*CompareTag means whether the gameObject contains the Tag you put into the     
            CompareTag statement.*/
		if (other.CompareTag("Boundary")||other.CompareTag("Enemy"))
		{			
			return;
		}

		if (explosion != null) 
		{
			Instantiate(explosion, transform.position, transform.rotation);
		}

		if (other.tag == "Player")
			
		{
			Instantiate (playerExplosion, other.transform.position, other.transform.rotation);
			gameController.GameOver ();
		}
		gameController.AddScore (scoreValue);
		Destroy (other.gameObject);
		Destroy (gameObject);
/*Here we're Destroying the Asteroid as soon as it collides with player or it goes out of the 
         Boundary(Remember! 'a' in Boundary) */
		if (other.CompareTag ("Boundary") || other.CompareTag ("Player")) 
		{
			Destroy (this.gameObject);
		}

	}

3. Try to understand the code, let me know if it works.

Hey! Here is the Image of Bolt’s Capsule Collider Component.
98712-bolt.jpg