Hey everyone, so im new to programming with unity and have been following some tutorials and such to learn. At the moment i am trying to create a shotgun like effect bullet spread within a 2D environment and have run into a bit of a snag.
The bullet effect works great with the code i currently have the issue is the direction the bullets are firing in, they always seem to generally move towards the top left of the screen instead of the direction the ‘cannon’ is pointing.
for (int i = 0; i < numberOfPellets; i++) {
Vector3 euler = transform.eulerAngles;
euler.z = Random.Range (0.0f, 90.0f);
bulletEmitter.transform.eulerAngles = euler;
GameObject tempBullet = Instantiate (bullet, bulletEmitter.transform.position, bulletEmitter.transform.rotation) as GameObject;
print ("FIRE!");
The code to fire the weapon is a basic if Input.GetButtonDown(“Fire1”)
hoping someone might be able to help me figure out the direction problem.
I’ve included a picture for reference.
Also, if you remove the eulerAngles code the cannon will shoot 1 bullet towards the mouse.
Thanks in advance,