- Home /
 
MuzzleFlash not working
please help i followed narutoisgreat1234's tutorial about muzzle flash exactly. but when i shoot the muzzle flash goes in random places like up down left right and sometimes even off the camera. how do i make it so the muzzle flash sticks to the barrel. it is a particleemitter and is 3d not a 2d plane. he is my script for the muzzle flash:
     var Range : float = 1000;
     var Force : float = 1000;
     
     var Clips : int = 20;
     
     var BulletPerClip : int = 30;
     
     var ReloadTime : float = 2.1;
     
         var Damage : int = 20;
     
         var BulletsLeft : int = 0;
         
             var ShootTimer : float = 0;
             
             var ShootCooler : float = 0.9;
             
             public var ShootAudio : AudioClip;
             
             public var ReloadAudio : AudioClip;
             
             var HitParticles : ParticleEmitter;
             
             var muzzleFlash : ParticleEmitter;
             
                 var muzzleCooler : float = 0.1;
                 
                 var muzzleFlashTimer : float = 0;
                 
                 var light1 : GameObject;
                 
                 var light2 : GameObject;
                 
                 var light3 : GameObject;
             
             var MuzzleSpeed : int = 200000;
             
                 var KeyTimer : float = 0;
                 
                  var KeyCooler : float = 1;
 
               function Start(){
     BulletsLeft = BulletPerClip;
     
     muzzleFlash.emit = false;
     
     HitParticles.emit = false;
     
 
               }
function Update () {
 if( KeyTimer > 0){
 
 KeyTimer -= Time.deltaTime;
 
 }
     if( KeyTimer > 0){
     
     KeyTimer = 0;
     
     }
 
 
               if( muzzleFlashTimer > 0){
muzzleFlashTimer -= Time.deltaTime;
  MuzzleFlashShow();
 
 
               }
if( muzzleFlashTimer < 0){
  muzzleFlashTimer = 0;
 
 
 
               }
         if( ShootTimer > 0){
         
         ShootTimer -= Time.deltaTime;
         
         }
         
         if( ShootTimer < 0){
         
            ShootTimer =0;
         
         }
         
         if( KeyTimer ==0){
         if(Input.GetKey(KeyCode.Mouse0) && BulletsLeft){
         if( ShootTimer == 0){
         
         
         PlayShootAudio();
             RayShoot();
             
             ShootTimer = ShootCooler;
             
             }            
             if( muzzleFlashTimer == 0){
 
                 muzzleFlashTimer = muzzleCooler;
                 
                                MuzzleFlashShow();
                                     
 
               }
}
} 
} 
function MuzzleFlashShow (){
 if( muzzleFlashTimer > 0){
 
     muzzleFlash.emit = false;
     
         light1.active = false;
          light2.active = false;
           light3.active = false;
     }
     
     
     if( muzzleFlashTimer == muzzleCooler ){
     
     
         muzzleFlash.transform.localRotation = Quaternion.AngleAxis( Random.value * 360 * MuzzleSpeed , Vector3.forward);
     
         muzzleFlash.emit = true;
     
         light1.active = true;
          light2.active = true;
           light3.active = true;
     }
 
               }
function RayShoot (){
     var Hit : RaycastHit;
             var DirectionRay = transform.TransformDirection(Vector3.forward);
             
             Debug.DrawRay(transform.position , DirectionRay * Range , Color.blue);
             if(Physics.Raycast(transform.position , DirectionRay , Hit, Range)){
             
             if(Hit.rigidbody){
             
             
             
             if( HitParticles){
             
             HitParticles.transform.position = Hit.point;
             HitParticles.transform.localRotation = Quaternion.FromToRotation(Vector3.forward, Hit.normal);
             HitParticles.Emit();
             
             Hit.rigidbody.AddForceAtPosition( DirectionRay * Force , Hit.point);
             Hit.collider.SendMessageUpwards("ApplyDamage" , Damage, SendMessageOptions.DontRequireReceiver);
             }
             }
             }
             
             
             BulletsLeft --;
             
             if(BulletsLeft < 0){
             
             BulletsLeft = 0;
             
             }
             
             if( BulletsLeft == 0 ){
             
             Reload();
             
             
             }
             }
             
             
 
               function Reload (){
     PlayReloadAudio();
  yield WaitForSeconds( ReloadTime);
  
          if(Clips > 0){
          
             BulletsLeft = BulletPerClip;    
              
 
               } }
function PlayShootAudio(){
     audio.PlayOneShot( ShootAudio);
 
               }
function PlayReloadAudio(){
audio.PlayOneShot( ReloadAudio);
}
how do i make it so it sticks to the barrel instead of going random places????
also here is a video showing the problem http://www.youtube.com/watch?v=3js2gQTO1FU&feature=youtu.be
Your answer
 
             Follow this Question
Related Questions
,Muzzle flash not working 1 Answer
My Grenade isnt working, help! 2 Answers
Time.timeScale does nothing 1 Answer