I am trying to add bullet spread to this script:
//Shoot a bullet
IEnumerator Shoot(int extraShot)
{
//Generate a random value
int randomVal = Random.Range(0, 180);
Vector3 spread = new Vector3(0, 0, randomVal-90);
//Add a bullet
GameObject bullet = Instantiate(bulletPrefab, firePoint.position, Quaternion.Euler(firePoint.rotation.eulerAngles + spread));
//Get Rigidbody2D
Rigidbody2D rb = bullet.GetComponent<Rigidbody2D>();
//Add a force
rb.AddForce(firePoint.up * bulletForce, ForceMode2D.Impulse);
yield return new WaitForSeconds(0);
}
I want the bullet to deviate once it is fired out of the firepoint. I have tried to changing the code myself by adding spread to the firepoint rotation but it only rotates the graphics of the bullet prefab instead of the direction it travels.