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 Dragonfly3r · Apr 19, 2015 at 10:36 PM · c#instantiatebulletgungun script

Bullets aren't firing / Bullet holes not instantiating correctly

I've been trying to make my bullets shoot out of my gun however I've run into a couple of problems. These being when I shoot the bullet it instantiates it but the bullet just stays in 1 position and doesn't accelerate out towards the object so you end up with a load of floating bullets with colliders on (until I put destroy script on them).

The other bug I'm experiencing is when I'm firing my gun I'm expecting bullet holes to appear when the bullet collides with a object or when my Raycast for the gun hits the object. The problem I'm facing however is that the bullet holes although they're showing up on the wall they're only facing in 1 direction instead of towards the player on the object. I have got an quaternion on the bullet hole so it should turn towards the player but instead it just faces a single direction and is thus not view-able by the player.

In regards to the bulletholes I have been checking with my other scripts where I have been using quaternions for rotating of gameObjects when raycasted with absolutely no luck with it happening even when I've tried copying the code in and manipulating it for my needs on this script.

Is anybody able to help me with these bugs?

Here is the bullet script which includes the script for the bullet-holes.

BulletScript

 public float maxDist;
 public GameObject decalHitWall;
 public float floatInFrontOfWall;

 [HideInInspector]
 public float lifeTime = 2.0f;
 [HideInInspector]
 public int bulletSpeed = 5;
 
 // Use this for initialization
 void Start () 
 {
     maxDist = 1000000000.0f;
     floatInFrontOfWall = 0.00001f;
 }
 
 // Update is called once per frame
 void Update () 
 {
     //transform.Translate(Vector3.down * Time.deltaTime * bulletSpeed);
     //rigidbody.AddForce(transform.forward * 3000);

     RaycastHit hit;
     Quaternion rayObjectRotation;

     if (Physics.Raycast(transform.position, transform.forward, out hit, maxDist))
     {
         if (decalHitWall && hit.transform.tag == "Level Parts")
         {
             Instantiate(decalHitWall, hit.point + (hit.normal * floatInFrontOfWall),
                 Quaternion.LookRotation(hit.normal));
         }
         Destroy(gameObject);
     }
 }

Here is the script I have set up for spawning of the bullet. RayShoot Code

     if (keyTimer == 0)
     {
         if (Input.GetMouseButton (0) && bulletsLeft > 0)
         {
             if (shootTimer == 0)
             {
                 PlayShootAudio();
                 RayFire();
                 Instantiate(bullet, bulletSpawn.transform.position, bulletSpawn.transform.rotation);
                 shootTimer = shootCooler;
                 keyTimer = keyCooler;
             }
Comment
Add comment · Show 1
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 siaran · Apr 20, 2015 at 02:47 PM 0
Share

//transform.Translate(Vector3.down Time.deltaTime bulletSpeed); //rigidbody.AddForce(transform.forward * 3000);

Well, your bullet isn't going to move with those lines both commented out.

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

3 People are following this question.

avatar image avatar image avatar image

Related Questions

WaitForSecond Corountine Sleep Time Varies 2 Answers

Need help with my gun script! 1 Answer

Which is better, shooting a bullet from camera or from the gun itself? 3 Answers

Setting bullet instansiate direction? help? 1 Answer

Objects instantiate at prefab location instead of playtime location 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