Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
1
Question by Danny Aaron · Mar 21, 2011 at 10:54 PM · fpsgunparticlemuzzleflash

Particles not appearing on impact, muzzle flash problems?

I'm having a problem with my muzzle flash and particles. I'm following the fps tutorial. I'm trying to use the Sparks prefab as my particles, and I set them as a child object of my gun. Also, I assigned muzzle_flash(the child of my gun) as my muzzle flash animation. However, when I shoot in the game I just get a white box as my muzzle flash. Also, my gun doesn't hit anything. I don't see sparks anywhere. I am using this shooting code for my machine gun:

var range = 100.0; var fireRate = 0.05; var force = 10.0; var damage = 5.0; var bulletsPerClip = 40; var clips = 20; var reloadTime = 0.5; private var hitParticles : ParticleEmitter; var muzzleFlash : Renderer;

private var bulletsLeft : int = 0; private var nextFireTime = 0.0; private var m_LastFrameShot = -1;

function Start () { hitParticles = GetComponentInChildren(ParticleEmitter);

 // We don't want to emit particles all the time, only when we hit something.
 if (hitParticles)
     hitParticles.emit = false;
 bulletsLeft = bulletsPerClip;

}

function LateUpdate() { if (muzzleFlash) { // We shot this frame, enable the muzzle flash if (m_LastFrameShot == Time.frameCount) { muzzleFlash.transform.localRotation = Quaternion.AngleAxis(Random.value * 360, Vector3.forward); muzzleFlash.enabled = true;

         if (audio) {
             if (!audio.isPlaying)
                 audio.Play();
             audio.loop = true;
         }
     } else {
     // We didn't, disable the muzzle flash
         muzzleFlash.enabled = false;
         enabled = false;

         // Play sound
         if (audio)
         {
             audio.loop = false;
         }
     }
 }

}

function Fire () { if (bulletsLeft == 0) return;

 // If there is more than one bullet between the last and this frame
 // Reset the nextFireTime
 if (Time.time - fireRate > nextFireTime)
     nextFireTime = Time.time - Time.deltaTime;

 // Keep firing until we used up the fire time
 while( nextFireTime < Time.time && bulletsLeft != 0) {
     FireOneShot();
     nextFireTime += fireRate;
 }

}

function FireOneShot () { var direction = transform.TransformDirection(Vector3.forward); var hit : RaycastHit;

 // Did we hit anything?
 if (Physics.Raycast (transform.position, direction, hit, range)) {
     // Apply a force to the rigidbody we hit
     if (hit.rigidbody)
         hit.rigidbody.AddForceAtPosition(force * direction, hit.point);

     // Place the particle system for spawing out of place where we hit the surface!
     // And spawn a couple of particles
     if (hitParticles) {
         hitParticles.transform.position = hit.point;
         hitParticles.transform.rotation = Quaternion.FromToRotation(Vector3.up, hit.normal);
         hitParticles.Emit();
     }

     // Send a damage message to the hit object          
     hit.collider.SendMessageUpwards("ApplyDamage", damage, SendMessageOptions.DontRequireReceiver);
 }

 bulletsLeft--;

 // Register that we shot this frame,
 // so that the LateUpdate function enabled the muzzleflash renderer for one frame
 m_LastFrameShot = Time.frameCount;
 enabled = true;

 // Reload gun in reload Time        
 if (bulletsLeft == 0)
     Reload();           

}

function Reload () {

 // Wait for reload time first - then add more bullets!
 yield WaitForSeconds(reloadTime);

 // We have a clip left reload
 if (clips > 0) {
     clips--;
     bulletsLeft = bulletsPerClip;
 }

}

function GetBulletsLeft () { return bulletsLeft; }

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by Michael 12 · Mar 22, 2011 at 12:28 AM

I had the exaxt same problem when I was following that tutorial so I feel your pain. Here follow this guys video tutorial, it helped me. He's a bit all over the place but gets the job done ;) http://www.youtube.com/watch?v=sYQQY76F8ac

Comment
Add comment · Show 4 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Danny Aaron · Mar 22, 2011 at 12:38 AM 0
Share

Thats the tutorial I was following, still same problem.

avatar image Michael 12 · Mar 22, 2011 at 01:15 AM 0
Share

Hmmm maybe copy and paste the script again, make sure everything is where it's supposed to be, if yur like me and new to this stuff it can be pretty easy to miss things. Even a simple spelling mistake can muck up the whole thing. Does Unity give you any error messages? If so check them for what line the error is on and then compare that to the code in the PDF document from the FPS tutorial.

avatar image Danny Aaron · Mar 22, 2011 at 11:44 PM 0
Share

Unity gives me the errors that my Windows is missing an update (SP1) and that there are two audio listeners in the scene. Would either of these cause a problem regarding muzzle flash and particles on impact?

avatar image Michael 12 · Mar 23, 2011 at 12:12 AM 0
Share

Well I don't know about that first bit, but your machine gun should have an Audio Source NOT a listener so I would take a look in the inspector and make sure that is set right.

avatar image
0

Answer by KnightChatX · Apr 17, 2011 at 07:55 AM

I'm experiencing the same problem, the sparks are showing up directly behind the camera no matter where I set it and will maintain a rotation behind the camera so that's why I can't see the sparks.

The other issue is the sparks are only visible in a top down view along the Y-Axis and only appear when firing directly in the sky or sometimes at the ground.

I reviewed the same tutorial, the muzzle flash and the gun you need to manually set the linkage to the associated textures.

I'm currently looking for a solution to the sparks problem, I'm using the default Sparks script that comes with Unity as well to test with.

Anybody have an answer how to fix this?

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

No one has followed this question yet.

Related Questions

How do I make a gun project a particle? 1 Answer

.Js Particle issue (probably easy for moderate coders) 0 Answers

How to position a gun on a FPS Charater 1 Answer

FPS gun clippes through walls 5 Answers

If (increasing/decreasing)? check if something is increasing or decreasing 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges