Particle Emitters, Tracer Fire

The topic says it all, currently in our game we’re shooting bullets that are set up like this.

Normal Fire
Transform
Cube (Mesh Filter)
Box Collider
-Is Trigger
Mesh Renderer (off)
Rigid Body
-Gravity Off
Ellipsoid Particle Emitter
-Max Min Emission: 1
-Ellipsoid 0,0,0
Particle Animator
Particle Renderer
-Stretched
-Velocity Scale: 0.1
NormalFire.cs

This prefab is created and fired at the target at whatever speed we set.

I think this stems from my lack of knowledge about how the particle systems work. I’m able to get all sorts of effects that I want when just working with the particle systems, but when they’re moving or affected by outside forces I’m a bit lost.

The kind of gunfire being aimed for is tracer style fire, so the line renderer really isn’t appropriate, and from what I understand it’s slightly more expensive, and this game is for the iPhone, so keep that in mind.

So what’s the problem? No matter what I seem to do, the particles don’t seem to act as if they’re just being given 50 units of velocity or force going the direction they are. The results I get firing are totally different than what I get just adding 50 units of local force to the emitter or animator.

When I fire, if its at 40 or 50, I dont see a thing, if its at 10, I see a single spot where they animate for a moment about 3 quarters of the way to their target. Does anyone have a good idea for using particle animators like this?

I’ve considered other options like just having a particle emitter and passing the correct values to it based on the vector difference of the player and the enemy, then giving it velocity, and having it turn on and off, or having multiple created with one shot and autodestruct on, but this seems like it wouldn’t be the best way. Meanwhile the invisible cubes would still have to be thrown, and the feedback wouldn’t always match up with the animations hitting when the cubes do.

EDIT: I was thinking more about this, and I think what’s happening is caused by this.

The particles themselves stretch based on their velocity relative to the emitter, but we’re moving the emitter. Is this how they work?

If so, is there any way to just create a particle and have it render without an emitter? Almost like a permenant particle that will allow stretching based on its own non relative velocity? Any ideas are welcome, or even something pointing to a tutorial or somewhere in the right direction. Nothing about this I could find in the help component files, but perhaps I missed them.

Hi.

You have found the problem. If you are only moving the emitter the particles won’t get stretched, but you can set the “Emitter velocity” to 1 or higher (I don’t remember the exact name, but the setting is in the emitter component) so the particles will be spawned with the velocity of the emitter.

PS You can’t use particles without an emitter.

Hope it helps.

If I understand that correctly, you’re moving a prefab containing a particle system? I think you’d get better results keeping the particle system still, where the gun is, and just have the particles move. Make the local Z velocity be a fairly high number so they get shot forward. Have “simulate in world space” on.

–Eric

The problem with not moving the object is, an invisible rigid body still needs to be thrown as a trigger so that the enemy knows when it’s being hit, and when there’s a miss. If I’m throwing randomized particles and invisible boxes, they’re not matching up.

Hence, the player would be getting incorrect feedback, a miss may hit and a hit may miss. I could stick a trail renderer on the backside of the cubes, and have it work like that, but the effect a trail renderer creates is not really suited for tracer fire. Does anyone know of a better way to achieve this aesthetic while having correct feedback?

PS. Thanks for the responses so far, they’ve confirmed what I’ve thought.

I’d use raycasting for this sort of thing, since bullets move too fast for the physics engine to handle. Then the particles are just sort of an “illustration” of what’s happening.

–Eric

Yes raycasting is a good way to do it.
You just raycast and see if it hits the enemy and then you spawn a bunch of particles so the user can see what’s happening.

Wait. I’m confused, if the desired effect is tracer fire, which would animate whether it hits or not, how would raycast be used to achieve that?

Basically, If you imagine for a second, you’re firing a machine gun from the hip randomly at a target. I want all the rounds to be visible with tracer fire, but obviously you’re only going to hit on some of them. I’m guessing there’s basically no good way to do this?

Raycasting. :slight_smile: Emit particles when firing, use raycasting to see if you hit or not.

–Eric

Alright sorry, I was trying to look at the Raycasting section of the Documentation, but only found a very technical explanation in the Script References.

Looks like I’ll be diving in to figure out what and how to use this feature next. Thanks for the help.

Edit: Is the intention of using this to find out, throwing particles and rays in raycasting from the same place at the same rate and seeing if they hit?

The goal was to get some randomization in the fire, but matching the randomization of the particle and the ray seems impossible, or is there a way to use raycasting to detect whether those individual particles hit? I’ll be looking into it with our programmer either way, but if anyone knows a place with a basic explanation of how raycasting works much obliged.

Thanks for all the help.

The MachineGun.js script in the FPS tutorial has an example of raycasting.

–Eric

Thanks! I will check that out. Can’t believe I missed that.