Hello I am looking for some help with making my shotgun have spread with its bullets. They spread just fine until i look up or down, then they start to shoot up to much or the left to much etc. This is my code:
public Transform Shootpoint1;
public Transform Shootpoint2;
public Transform Shootpoint3;
public Transform Shootpoint4;
public Transform Shootpoint5;
public Transform Shootpoint6;
public GameObject Bullet;
public float Bullet1RX;
public float Bullet1RY;
public float Bullet1RZ;
public float Bullet2RX;
public float Bullet2RY;
public float Bullet2RZ;
public float Bullet3RX;
public float Bullet3RY;
public float Bullet3RZ;
public float Bullet4RX;
public float Bullet4RY;
public float Bullet4RZ;
public float Bullet5RX;
public float Bullet5RY;
public float Bullet5RZ;
public float Bullet6RX;
public float Bullet6RY;
public float Bullet6RZ;
void Update ()
{
if (Input.GetMouseButtonDown(0))
{
Fire();
}
}
void Fire ()
{
Bullet1RX = Random.Range(-3, 3);
Bullet1RY = Random.Range(-3, 3);
Bullet1RZ = Random.Range(-3, 3);
Bullet2RX = Random.Range(-3, 3);
Bullet2RY = Random.Range(-3, 3);
Bullet2RZ = Random.Range(-3, 3);
Bullet3RX = Random.Range(-3, 3);
Bullet3RY = Random.Range(-3, 3);
Bullet3RZ = Random.Range(-3, 3);
Bullet4RX = Random.Range(-3, 3);
Bullet4RY = Random.Range(-3, 3);
Bullet4RZ = Random.Range(-3, 3);
Bullet5RX = Random.Range(-3, 3);
Bullet5RY = Random.Range(-3, 3);
Bullet5RZ = Random.Range(-3, 3);
Bullet6RX = Random.Range(-3, 3);
Bullet6RY = Random.Range(-3, 3);
Bullet6RZ = Random.Range(-3, 3);
GameObject Bullet1 = (GameObject)Instantiate(Bullet, Shootpoint1.position, Shootpoint1.rotation);
Bullet1.GetComponent<Transform>().Rotate(Bullet1RX, Bullet1RY, Bullet1RZ);
Bullet1.GetComponent<Rigidbody>().AddRelativeForce(Shootpoint1.forward * -1, ForceMode.Impulse);
Destroy(Bullet1, 5);
GameObject Bullet2 = (GameObject)Instantiate(Bullet, Shootpoint2.position, Shootpoint2.rotation);
Bullet2.GetComponent<Transform>().Rotate(Bullet2RX, Bullet2RY, Bullet2RZ);
Bullet2.GetComponent<Rigidbody>().AddRelativeForce(Shootpoint2.forward * -1, ForceMode.Impulse);
Destroy(Bullet2, 5);
GameObject Bullet3 = (GameObject)Instantiate(Bullet, Shootpoint3.position, Shootpoint3.rotation);
Bullet3.GetComponent<Transform>().Rotate(Bullet3RX, Bullet3RY, Bullet3RZ);
Bullet3.GetComponent<Rigidbody>().AddRelativeForce(Shootpoint3.forward * -1, ForceMode.Impulse);
Destroy(Bullet3, 5);
GameObject Bullet4 = (GameObject)Instantiate(Bullet, Shootpoint4.position, Shootpoint4.rotation);
Bullet4.GetComponent<Transform>().Rotate(Bullet4RX, Bullet4RY, Bullet4RZ);
Bullet4.GetComponent<Rigidbody>().AddRelativeForce(Shootpoint4.forward * -1, ForceMode.Impulse);
Destroy(Bullet4, 5);
GameObject Bullet5 = (GameObject)Instantiate(Bullet, Shootpoint5.position, Shootpoint5.rotation);
Bullet5.GetComponent<Transform>().Rotate(Bullet5RX, Bullet5RY, Bullet5RZ);
Bullet5.GetComponent<Rigidbody>().AddRelativeForce(Shootpoint5.forward * -1, ForceMode.Impulse);
Destroy(Bullet5, 5);
GameObject Bullet6 = (GameObject)Instantiate(Bullet, Shootpoint6.position, Shootpoint6.rotation);
Bullet6.GetComponent<Transform>().Rotate(Bullet6RX, Bullet6RY, Bullet6RZ);
Bullet6.GetComponent<Rigidbody>().AddRelativeForce(Shootpoint6.forward * -1, ForceMode.Impulse);
Destroy(Bullet6, 5);
}
It may be a little hard on the eyes so i am sorry. I have read some posts where they say to add a Lookat somewhere but i dont understand. Thanks in advance.