- Home /
How to make a muzzle flash
I already use bullets in my game, but i am seriously thinking that i need to change it to muzzle flash, because my actual system requires a high powerfull hardware and do a big size change to my FPS.
Is there a tutorial or something to make a muzzle flash particle? Everything i tried until now failed and i want something real.
Everything i tried until now failed and i want something real. : can you give examples of what you have tried? What was the expected result, and what was the actual result?
I want to do a muzzle flash. When you use fire 1 (left mouse button), a bullet (a different one that i already made and it's better than the older version) spawns AND a muzzle flash, like a particle.
Basically, when you shoot, a "fire" particle appears for one second and then disappears, but i want to do one that doesn't bug if you shoot many times in a short period of time.
I tried using just cubes with images, but it doesn't work as expected, and i only found one single muzzle flash particle in ALL the internet, and it's buggy and heavy.
I am trying to make something that make the player feel that he is shooting a REAL weapon. Something nice.
The results i had until now were: - Black background muzzle flash EVEN using transparency,shaders and marked options. - Bugged particles. - Errors during spawn. - $$anonymous$$uzzle flash hiding the bullet as it spawns - Conflict between the two.
Answer by Cherno · Jul 23, 2016 at 05:49 PM
First of all, I don't recommend using particles for a muzzle flash effect. The reason is that particles are only shown from one angle, and muzzle flashes in real life typically don't look like a ball of fire but rather like a longish flame spurting out of the barrel, plus additional flashes depending on the muzle break or flash hider on the gun. Most games use a combination of planes with alpha-masked textures on them, it's what I used for my sentry gun:
Just two planes perpendicular to each other with a long flash, and another one at flat against their "base" witha round flash one for where the bullet leaves the barrel.
For the issue of rapid fire, see this thread:
(Rapid fire) How to accurately wait for a very short amount of time?
Thanks! ^.^ i am almost finishing it, and i know it will work. Could you make this an answer? So i can accept it.
Upvoted. The only reason I added an answer is because the OP posted again : http://answers.unity3d.com/questions/1222973/how-to-spawn-a-muzzleflash.html
Answer by AlucardJay · Jul 30, 2016 at 11:22 AM
The Angry Bots demo has a perfect example of using a pyramid mesh with a 'muzzle flash' texture, and a script to rotate the mesh while the gun is being fired.
From the Angry Bots demo :
The 'muzzle flash' mesh is a child of the gun, positioned at the end of the barrel. Also note the rotation, as this will determine what axis the mesh is rotated on in the script.
Now there is a script called MuzzleFlashAnimate.js. Quite simply :
#pragma strict
function Update () {
transform.localScale = Vector3.one * Random.Range(0.5,1.5);
transform.localEulerAngles.z = Random.Range(0,90.0);
}
Per frame (Update), this randomly : scales the object; rotates the object on the Z axis.
Now in the firing script AutoFire.js, this can be heavily abbreviated to just :
var muzzleFlashFront : GameObject;
function Start()
{
muzzleFlashFront.SetActive (false);
}
function Update ()
{
if(Input.GetButtonDown("SHOOT"))
{
muzzleFlashFront.SetActive (true);
}
if(Input.GetButtonUp("SHOOT"))
{
muzzleFlashFront.SetActive (false);
}
}
If the shoot button is pressed, enable the muzzleflash gameobject. If the shoot button is released, disable the muzzleflash gameobject.
When the muzzleflash object is enabled, the script MuzzleFlashAnimate starts working, and the muzzleflash effect is rotated and scaled, creating the illusion of a muzzleflash.
This is the simplest way of achieving the effect. But very effective, as stated in the original answer by Cherno (you could expand on this basic method as described by Cherno).
Answer by $$anonymous$$ · Jul 23, 2016 at 07:55 PM
Gabemeister1201 explains on how to do it, it's quite simple: https://www.youtube.com/watch?v=XGG0VwMieGc watch from 0:00 to 7:25.
Your answer
Follow this Question
Related Questions
How to make Low Poly Terrain (free) 1 Answer
Can't create a new shader 1 Answer
How to create a login system online? 1 Answer
Basic Scripting help 2 Answers
character creation 2 Answers