Question by 
               PandaCatPlayz · Jun 26, 2020 at 09:21 AM · 
                instantiateprojectilerigidbody.addforce  
              
 
              Help I use rigidbody.addforce to fire projectiles an it randomly doesn't go to the crosshair!
public GameObject shurikenProjectile; public List projectileSpawnTransforms = new List(); public int damage = 10; public float speed = 10f; public float range = 100f;
     public bool canShoot;
     public int maxAmmo = 30;
     public int currentAmmo;
     public float reloadTime = 1f;
     public bool isReloading = false;
     public bool canReload = true;
     public Text curAmmoNumber;
 
     public Camera fpsCam;
     public Animator abilitiesAnimator;
     public GameObject leftShurikenPoint;
     public GameObject rightShurikenPoint;
     public float betweenShots;
 
     public float timeRemaining;
     public float timerMax = 1f;
     public float currentAmmoSlider;
     public Slider reloadSlider;
     public GenjiDash dashScript;
     public Text dashControl;
     public AlphaChange dashText;
     public float ultDuration;
     void Start()
     {
         curAmmoNumber.text = "30";
         currentAmmo = maxAmmo;
         canShoot = true;
         timeRemaining = timerMax;
     }
     void Update()
     {
         if(isReloading == false)
         {
             timeRemaining = currentAmmoSlider;
         }
         reloadSlider.value = CalculateSliderValue();
     
         if(isReloading)
         {
             timeRemaining += Time.deltaTime;
         }
         if(isReloading)
         {
             return;
         }
         if(currentAmmo <= 0)
         {
             if(canReload)
             {
                 timeRemaining = 0;
                 StartCoroutine(Reload());
                 canShoot = false;
             }
         }
         if(Input.GetButtonDown("Reload"))
         {
             if(currentAmmo < 30)
             {
                 if(canReload)
                 {
                     timeRemaining = 0;
                     StartCoroutine(Reload());
                     canShoot = false;
                 }
             }
         }
         if(canShoot)
         {
             if(Input.GetButtonDown("Fire1"))
             {
                 canShoot = false;
                 StartCoroutine(Shoot1());
             }
         }
         if(canShoot)
         {
             if(Input.GetButtonDown("Fire2"))
             {
                 canShoot = false;
                 StartCoroutine(Shoot2());
             }
         }
         curAmmoNumber.text = currentAmmo.ToString();
     }
     public IEnumerator Reload()
     {
         StartCoroutine(dashText.ChangeAlpha());
         StartCoroutine(dashScript.shurikensReloading());
         isReloading = true;
         Debug.Log("Reloading");
         abilitiesAnimator.SetBool("Reloading", true);
         yield return new WaitForSeconds(reloadTime - .25f);
         abilitiesAnimator.SetBool("Reloading", false);
         yield return new WaitForSeconds(.25f);
         isReloading = false;
         currentAmmoSlider = 1f;
         currentAmmo = maxAmmo;
         canShoot = true;
     }
     public IEnumerator Shoot1()
 {
     canReload = false;
     int shurikensFired = 0;
     while (shurikensFired < 3)
     {
         shurikensFired++;
         GameObject projectileInstance = Instantiate(shurikenProjectile, transform.position, projectileSpawnTransforms[1].rotation);
         projectileInstance.GetComponent<Rigidbody>().AddForce(projectileInstance.transform.forward * speed, ForceMode.VelocityChange);
         currentAmmo--;
         currentAmmoSlider -= 0.0333f;
         Debug.Log("Wait1");
         yield return new WaitForSeconds(betweenShots);
     }
     yield return null;
     canShoot = true;
     canReload = true;
 }
 public IEnumerator Shoot2()
 {
     canReload = false;
     GameObject projectileInstance1 = Instantiate(shurikenProjectile, transform.position, projectileSpawnTransforms[0].rotation);
     projectileInstance1.GetComponent<Rigidbody>().AddForce(projectileInstance1.transform.forward * speed, ForceMode.VelocityChange);
     currentAmmo--;
     currentAmmoSlider -= 0.0333f;
     Debug.Log("Wait2");
     yield return new WaitForSeconds(betweenShots);
     GameObject projectileInstance2 = Instantiate(shurikenProjectile, transform.position, projectileSpawnTransforms[1].rotation);
     projectileInstance2.GetComponent<Rigidbody>().AddForce(projectileInstance2.transform.forward * speed, ForceMode.VelocityChange);
     currentAmmo--;
     currentAmmoSlider -= 0.0333f;
     Debug.Log("Wait2");
     yield return new WaitForSeconds(betweenShots);
     GameObject projectileInstance3 = Instantiate(shurikenProjectile, transform.position, projectileSpawnTransforms[2].rotation);
     projectileInstance3.GetComponent<Rigidbody>().AddForce(projectileInstance3.transform.forward * speed, ForceMode.VelocityChange);
     currentAmmo--;
     currentAmmoSlider -= 0.0333f;
     canShoot = true;
     canReload = true;
 }
 float CalculateSliderValue()
 {
     return(timeRemaining / timerMax);
 }
 public IEnumerator shurikenStop()
 {
     canShoot = false;
     canReload = false;
         
     yield return new WaitForSeconds(ultDuration + 2f);
     canReload = true;
     canShoot = true;
 }
}
               Comment
              
 
               
              Your answer
 
 
             Follow this Question
Related Questions
Instantiated object start rotation 0 Answers
enemy shoots faster as it gets closer to player 1 Answer
How to make an object shoot a projectile? 4 Answers
Projectile disappears instantly after appearing. 1 Answer
transform.forward problem 2 Answers
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                