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 ypanos · Jun 04, 2015 at 03:38 AM · instantiateprojectile

Bullet instantiates sometimes in wrong posiiton

enter code hereI am having a script where projectiles (bullet ) are instantiated when player fires at high rate. Unfortunatly some times for example when firing continuesly some bullets instantiate on wrong spot. using the FixedUpdate instead of the Update function corrected most of the problem buit still some bulelts are not instantiated at the correct position that is in front of the gun. As a result the weapon fires bullets on two directions. Bullets are being instantiated at a high rate. Is there a way to correct this?

 void FixedUpdate () {
 
         if (Input.GetMouseButton (1) && !playerMovement.crouchState )  {
             if(Input.GetMouseButton(0) &&  Time.time > nextFire){
 
                 nextFire = Time.time + fireRate;
 
                 GameObject cloneBullet = Instantiate(bullet,transform.position,transform.rotation)    as GameObject;
                 muzzleFlash.animation.Play();
 cloneBullet.rigidbody.AddForce(cloneBullet.transform.forward*bulletSpeed);
                 if(!audioPlayed){
                 audio.clip = fireSFX;
                 audio.Play();
                 
                 audioPlayed = true;
                 }
                 Destroy(cloneBullet.gameObject,2);
                 audioPlayed = false;
             }
         }else{
 
         }
     
     }

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 devPhil · Jun 04, 2015 at 05:06 AM 0
Share

Are the bullets colliding with each other and therefor moving in a different direction/get pushed away from the spawn point? If this is the case maybe have the bullet collides ignore each other (by layers).

avatar image ypanos · Jun 04, 2015 at 07:59 AM 0
Share

I do not think that the bullets collide because they are ravelling on a straight line. The problem is that on ket's say every 5 bullets the other 2 are going straigh to the wrong direction. I noticed that firirn once at a time it is much better. I am wondering maybe if the fire rate has to do something with the functions that are called i mean the time interval.

Anyway i will lokk at it and let you know. thanks

avatar image devPhil · Jun 04, 2015 at 08:18 AM 0
Share

Well, considering they are rigidbodies and you spawn them in the same place they want to push away from each other and bounce off each other when you add a force to them. Try adding them to a layer and make them ignore that layer :)

avatar image hopper · Jun 07, 2015 at 05:42 AM 1
Share

For making a gun, I would recommend the Raycast functions inside of the Physics class rather than spawning an actual object to fly across the screen. It's just that unless we're really in the $$anonymous$$atrix, we can't see bullets get shot from a gun without some form of slow motion software. Now if you were trying to do a slow motion cam of the guy getting hit where the camera follows the bullet, that would be a reasonable use.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

Fire Projectile based on Model rotation 1 Answer

Velocity and AddForce Problems 0 Answers

Proper way to instantiate projectile in PUN 1 Answer

Instantiate projectile rotation 2 Answers

Want to instantiate projectile in direction character is moving. 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