Muzzle flash not reliable for rapid-fire weapons

I want to add a muzzle flash to my firing submachinegun, it shoots at about 12 rounds per second as a real-life SMG would. Now, at this rate, most of the time the flash isn’t created/shown, only if the timescale is lowered to slow-motion will every shot show a muzzle flash. It doesn’t matter how I create the muzzleflash, I have tried the following methods and they were all unreliable:

  1. Instatiating a particle system prefab at game start, disabling the emitter, and only enabling it for a short period (0.1 seconds) every shot
  2. Instantiating a particle system prefab for every shot, and destroying it again after 0.1 seconds.

Is there any way to make muzzle flashes for rapid-fire weapons more reliable?

I use a 2d texture on a plane in front of my guns, and it just renders when I am shooting, did you try this? edit: I also made a spinning animation so it doesn't have the "same" flash every time, the flash is rotated with a particle/additive shader

I'm thinking about doing it with a plane, but what counts is wether it works reliably with a high rate of fire.

1 Answer

1

I got a reliable solution working, here it is:

var Muzzle : GameObject;
var MuzzleFlashPrefab : GameObject;
var MuzzleFlashClone : GameObject;
var MuzzleFlashList : List.<GameObject>;

function DrawMuzzleFlash()
{
	MuzzleFlashClone = Instantiate(MuzzleFlashPrefab, Muzzle.transform.position, Muzzle.transform.rotation);
	MuzzleFlashList.Add(MuzzleFlashClone);
	MuzzleFlashClone.transform.localScale = Vector3(Random.Range(3.0, 4.0), Random.Range(3.0, 4.0), Random.Range(3.0, 4.0));
	yield WaitForSeconds(0.2);
	Destroy (MuzzleFlashList[0]);
	MuzzleFlashList.RemoveAt(0);
}

Iz that c#

@Luizr - No, it is Javascript/Unityscript.

Oh my, necro much, Luizr? ;) This was the very first project I ever worked on, I switched to C# after my second one because of the much better documentation and support available, and because C# has a broader application field (that's how I see it in general, after all).