How to create particle on object?

Hey everyone,

I’m asking for help in the Argon Assault lessons, specifically getting the explosion particles to play when the enemy is hit with the particles.

I know the code works because I hear the audio source play when the enemy is destroyed, but the particle effect is never played. I think the issue is that I can’t create the particle on the position of the enemy, but viewing the game running in 2by3 mode doesn’t show the effect being created at all, even though again I hear the audio so I know the code itself is working.

Cheers everyone

EDIT: I just wanted to say that I can confirm that it’s the location that is the issue. After increasing the size of the particle, it’s being created way below the object terrain itself, so my problem is the inability to create the explosion at the same location of the destroyed ship, even when using ‘Instantiate(deathFX, transform.position, Quaternion.identity);’, so is there a way to set the Origin of the object like there is in Blender?

Check your deathFX prefab is at 0,0,0 because its instantiating at the transform.position of the object its attached to which is local 0,0,0 if you have a transform set to anything but 0 it will be offset from the position.

I can confirm its at 0,0,0, but even at crazy numbers such as 0,60,0 its position never changes it seems.

Thoughts?

Hi Arthur,

First of all, check if your deathFX got spawned in your scene. You could add a little test script to the prefab, which logs a message into your Console. It might well be that the instantiated game object gets destroyed immediately.

Also check your Hierarchy while playing your game. Does a new game object appear? Maybe for a brief moment? Or longer? If it remains in the Hierarchy, pause your game and double click on the game object. Maybe your deathFX got spawned at the wrong position.

As Marc indicated, the different spaces in Unity can be a bit tricky.

I already know that it spawns, it just does way below the destroyed enemy instead of on it. Is there a code I can write to just have it create at the object’s location?

Below? Is it falling? If not, does it appear at the same position or with the same offset relative to the destroyed enemy?

The best would be to log the transform.position of your enemy and your instantiated deathFX into your console.

It’s not falling, it just spawns below the object by a considerable amount.

Here’s the print of many particles to many destroyed ships:

particle location = (11.0, -1.0, 0.9)

particle location = (6.2, -1.0, -0.9)

particle location = (11.4, -1.0, 2.4)

You can see that -1 is the common variable here, and I checked the transform of the particle and its 0,0,0, so I still can’t figure out why that’s the case. Although I think -1 maybe the bottom of the the level, so it’s being created on the ground, maybe?

Thoughts?

And where is the enemy? I’m wondering if your enemy has got a child game object with an offset. Could you share screenshots of your Hierarchy? To which game object is the script attached which instantiates the deathFX? transform.position refers to that game object and its Transform respectively.

The enemy and particle have the exact same transforms.

Script is attached to a created empty object that I then added the ship model to. I can confirm that when you attach the script to either the ship model or the object with the ship model in it, it yields the exact same results.

Could you upload your project folder to GitHub without the Library and Temp folders? If you do not know how to do that, please watch Ben’s videos on version controlling.

I’d like to look into your project.

I uploaded it, do I just paste a link here? Should the link have my name and the name of the project in the address right after github.com?

That’s correct. Here is an example for Ben’s and Rick’s repo. Check your link in an icognito tab in your browser because it might be that your repo is private. If it is, make it public, please.

Sorry for the late reply, I forgot the password to github so I wasn’t allowed in for a bit, haha!

Here’s the link: https://github.com/Arthur-Mars/Argon-Assault-Udemy

Couple of things to point out tho:

  1. I’ve been creating my own low poly assets, so the size of my project level is considerably smaller than the actual assets (my terrain was around 2,000 faces more or less, in comparison to the average terrain from the tutorials that were well over 100k), I imagine this might be a reason for the issue, but I’m not sure.

  2. The actual controls for moving the ship are different from the course (I’m not using cross platform libraries), and I’m using a path engine that’s not the same as the circuit one in the standard assets, but I’m confident that those aren’t the reason for the issue, as I don’t see how they relate to the issue at hand.

Finally, I’m also facing the issue of creation in the wrong location with the bullet particles as well. They’re being fired when I press the fire button, but don’t come out of the ship, even though when they fired at launch it was always on the ship’s location at all times.

Hope this helps you figuring out what the issue is.

Cheers Nina, thank you for your time.