0

I'm working on a game where you fire ammo at enemy aircraft that are passing overhead. When the ammo collides with an aircraft, a particle system prefab is instantiated. This all works fine, except when the aircraft transforms to the left half of the display, the explosion doesn't happen. It works fine on the right half of the screen. Code is below: This was from an online tutorial which I modified to add the explosions. The aircraft gets destroyed on collision, but the explosions only happen on the right half of the display. ammoExplosion is a public gameobject that is defined in the class and assigned in the inspector. Any advice is appreciated.

void OnTriggerEnter2D(Collider2D collider){
    if(collider.gameObject.tag == "Ammo"){
        GameObject e = Instantiate (ammoExplosion) as GameObject;
        e.transform.position = transform.position;
        e.renderer.sortingLayerName = "Foreground";
        e.renderer.sortingOrder = 13;
        Destroy (transform.gameObject); // Destroy fighter.
        Destroy (collider.gameObject);  // Destroy ammo.
        Destroy (e,0.7f);
    }
}
Steven
  • 166,672
  • 24
  • 332
  • 435
jadkins4
  • 903
  • 7
  • 18
  • 34

3 Answers3

1

Most commonly I had the some issues with positioning and particle systems is when I didn't set the position in the `Instantiate' method:

Change to this:

GameObject e = (GameObject)Instantiate(ammoExplosion, transform.position, Quarternion.identity);
AgentFire
  • 8,944
  • 8
  • 43
  • 90
0

Maybe it's a Simulation Space problem in the Particle System config. panel? You probably should be using "world".

Fliperamma
  • 106
  • 8
0

I finally found the answer and it was due to a dumb mistake. I had mistakenly attached a script to the explosion prefab. When I removed the script, everything worked perfectly. Thanks for the suggestions. I appreciate them.

jadkins4
  • 903
  • 7
  • 18
  • 34