How do you make particle system follow a game object?

I’m currently making a space invaders clone and I want to make it so that when my player’s laser collides with one of my enemies, that enemy will begin smoking like it’s taken serious damage. I have been able to have the particle system appear once the enemy is hit but I can’t get the particle system to follow the movement of the enemy. It stays in the exact place it was instantiated at. And once the enemy is killed the particle system continues to exist. Can anyone link me to a walkthrough for this or give me some tips? Thanks in advance.

Make the game object with the particle system a child of the other object.

1 Like

How do I do that? I had attached my particle system prefab named Smoke to my enemy in the hierarchy but then it the enemy starts smoking right away rather than after it has been hit.

I’m guessing that you instantiate the particle system prefab when you need it. That makes it a root object, though. After instantiating, parent it to the enemy:

particleSystemObject.transform.parent = enemyObject.transform;
5 Likes

Umm, the problem with this is if you make the particle system a child of the parent and you want to destroy the parent you would be destroying the particle system too which would make your particle not play…So, the question still needs to be answered here. Unfortunately, i’m wondering the same thing: How do you make particle system follow a game object?..

I think the answer will be almost the same :roll_eyes:

with the child befor the parent will be destroyed:

particleSystemObject.transform.parent = null;

without to be a child (be careful and check if this object isn’t destroyed)

void Update () {
if (followedObject.activeSelf)
gameObject.transform.position = followedObject.transform.position;
}
1 Like

Just make an empty game object, place the ship and the particle systems as children. They will be linked and you can destroy either one.

yourParticleSystem.Play();
Destroy(enemyObject, yourParticleSystem.main.duration);

You’ll need to declare the particle system as a variable.

[SerializeField] private ParticleSystem yourParticleSystem;

Edit:
It’s usually a good idea to set your duration a little longer than your particle’s lifetime. Duration is default 5f (5.00) so if you make your particle life time set to say 2, then make the duration something like 2.25 or whatever looks good. Otherwise, it’ll destroy the very instant it finishes which doesn’t look that smooth, in my opinion, for most situations.

How do you change the duration?