Particle System emitting at wrong location

Hi!
I’ve got a BulletPrefab with a Particle System attached to it (as child). Hitting the FireButton instatiates clones of my bullet. Everything’s working fine so far. I want the Particle System to emit whenever a bullet hits a collider (obstacles, other players and so on) at the exact position where the bullet hits said colliders. This only works for the first time. I start the game, shoot at an enemy1 and the particle effect appears right there where it collides with enemy1. Shooting enemy2 results in the particle effect appearing at the position from enemy1. That is obviously not what I want. I need the particle effect to appear on different locations, exactly there where the Bullet hits an collider.

Here’s the code I wrote. It’s attached to the BulletPrefab.

void OnTriggerEnter2D(Collider2D otherCollider){

		GameObject.FindGameObjectWithTag ("Splash").GetComponent<ParticleSystem> ().transform.parent = null;
		GameObject.FindGameObjectWithTag ("Splash").GetComponent<ParticleSystem> ().Play ();
	}

The bullets are destroyed as soon as they hit a collider and to prevent the destruction of the particle System as well I need to detach it from its parent.

So here’s my question: What can I do to move the Particle Systems location to wherever the new instatiated bullet hits a collider?

Thanks in advance! And if you need more information, just let me know.

Attach this to bullet prefab:

var ps : GameObject;

function Update(){
     var hit : RaycastHit2D;
     var ray : Ray = Camera.main.ScreenPointToRay(Input.mousePosition);
     if(Physics.Raycast2D(ray,hit){
          var go = Instantiate(ps,hit.position,hit.rotation);
          Destroy(this.gameObject);
     }
}

Next create a prefab for particles.
Attach this to particlePrefab:

function Update(){
     if(!this.GetComponent(ParticleSystem).IsAlive){
          Destroy(this.gameObject);
     }
}

Not tested, Have fun.

Please check your particle system simulation space. If it is attached as a child, make it local instead of world.
184847-ps.png

I’ve got it!

Instead of having a Particle System as child of the ShotPrefab, I created a Particle System Prefab. In the shotscript (which is attached to the shotPrefab) I wrote this little piece of code:

public GameObject particlePrefab;
public Transform shot1;

void OnTriggerEnter2D(Collider2D otherCollider){

		
Instantiate( particlePrefab, shot1.position, shot1.rotation);


	}

In the Inspector just assign shot1 as your bullet Prefab and there you go.
Thanks Bryckout for the help! Two thumps up!