- Home /
 
 
               Question by 
               aryiaxd · Jun 14, 2021 at 06:58 PM · 
                raycastbulletgunbullethole  
              
 
              How do I create bullet hole for my gun?
I want to create a gun I followed a tutorial but my Bullet holes are not in the correct position
 GameObject bulletHole =  Instantiate(bulletHole, hit.point + (hit.normal * .1f), Quaternion.FromToRotation(Vector3.forward, hit.normal));
 
               my entire script
 void Update()
     {
         
         if (allowButtonHold) {
             shooting = Input.GetKey(KeyCode.Mouse0);
         } else { 
             shooting = Input.GetKeyDown(KeyCode.Mouse0);
         }
 
         if (Input.GetKeyDown(KeyCode.R) && bulletsLeft < magazineSize && !reloading) Reload();
 
         if (bulletsLeft <= 0) { Reload(); }
 
         if (readyToShoot && shooting && !reloading && bulletsLeft > 0) {
             bulletsShot = bulletPerTap;
             Shoot();
         }
 
     }
 
     private void Reload() {
         reloading = true;
         Invoke("ReloadFinished", reloadTime);
     }
 
     private void ReloadFinished() {
         bulletsLeft = magazineSize;
         reloading = false;
     }
 
     private void Shoot() {
 
         //readyToShoot = false;
 
         Debug.Log(bulletsLeft);
 
         float x = Random.Range(-spread, spread);
         float y = Random.Range(-spread, spread);
 
         Vector3 direction = camera.transform.forward + new Vector3(x,y,0);
         
         if (Physics.Raycast(camera.transform.position, direction, out hit, range)) {
             Debug.Log(hit.collider.name);
         }
 
         GameObject bulletHole =  Instantiate(bulletHole, hit.point + (hit.normal * .1f), Quaternion.FromToRotation(Vector3.forward, hit.normal));
 
         bulletsLeft--;
         bulletsShot--;
 
         Invoke("ResetShot()", timeBetweenShooting);
 
         if (bulletsShot > 0 &&  bulletsLeft > 0)
         Invoke("Shoot()", timeBetweenShots);
     }
 
     private void ResetShot() {
         readyToShoot = true;
     }
 
               thanks
               Comment
              
 
               
              Your answer
 
             Follow this Question
Related Questions
Use transform.LookAt with Raycast with a delayed bullet? 1 Answer
Need coding help with fps 0 Answers
Gun Script 1 Answer
shooting problem with raycasting 1 Answer