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
0
Question by Mystic 2628 · Apr 05, 2014 at 12:12 PM · a

Bullets firing Bullets?

I've been trying to get some bullets to instantiate at the barrelEnd position and move forwards towards the player, but it's turned up interesting results. Basically, when i fire a bullet, it moves forwards but then instantiates a new bullet on the bullet i just fired as it travels towards the player. This means that one bullet becomes two,then two bullets become four and it keeps increasing exponentially. This causes a lot of lag and has pretty much stopped my progress. After experimenting with some different ideas, I ended up with a bullet that fired guns, a gun that fired it's barrel and bullets that sit still in the barrel but don't increase exponentially.

I know that the problem is caused because bullets are instantiating on bullets, so that means they'll even spawn on clones of bullets. Those print commands were for debugging stuff, so yea.

 #pragma strict
 
 public var PistolBullet : Rigidbody;
 public var barrelEnd : Transform;
 
 
 function Update ()
 {
     
     if(Input.GetKeyDown(KeyCode.Space))
     {
     
         print ("bbbb");
         var BulletInstance : Rigidbody;
         print ("vvvv");
         BulletInstance = Instantiate(PistolBullet, barrelEnd.position, barrelEnd.rotation);
         print ("Debug thingy");
     }
 }
 
 
 function OnCollisionEnter (col : Collision)
 {
     if(col.gameObject.name == "Bullet Time Chamber 01")
     {
         Destroy(col.gameObject);
     }
 }
 
 
Comment
Add comment · Show 4
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 HarshadK · Apr 05, 2014 at 12:28 PM 0
Share

What does this DestroyBullet() function do? Can you post its code?

avatar image Gruffy · Apr 12, 2014 at 04:25 PM 0
Share

Are you keeping Space held down ?

Try (Input.Get$$anonymous$$eyUp($$anonymous$$eyCode.Space)) this will only register when you lift your finger up from the space bar. Let me know bud. Cheers. Gruffy

avatar image joshpsawyer · Apr 12, 2014 at 04:28 PM 0
Share

What scripts, if any, are on your bullet prefabs? If your bullets are increasing exponentially, then it's likely the problem lies there.

avatar image Mystic 2628 · Apr 17, 2014 at 08:38 PM 0
Share

Alright guys. Problems solved. I just had to tweak the barrel position and move the script onto the gun rather than the bullet.

Now, Time to add a slowmotion feature. This should be fun.

0 Replies

· Add your reply
  • Sort: 

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

23 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

my STFPSC script has errors can anyone help me? 0 Answers

Add Weapon 1 Answer

Networking 0 Answers

Black and white effect 0 Answers

Changing the code from collision to button 5 Answers


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