How to make projectiles shoot diagonally?

Hello all, Im trying to make a 2D “spread shot” where 3 projectiles are instantiated in 3 different directions. One straight forward and 2 diagonals up and down. I feel like there is a simple way to do this that i’m not figuring out.

Here’s my code:

public GameObject Bulletprefab;

void Update ()
	{
		if (Input.GetKeyDown (KeyCode.RightShift)) 
		{
			Shoot ();
		}
	}
	public void Shoot()
	{
		GameObject Bullet = Instantiate (Bulletprefab, transform.position, transform.rotation);
	}

}

There are lots of ways you could do this. An easy visual way is to create a reference to 3 public Transforms in your code.

public Transform shootDirection1, shootDirection2, shootDirection3;

Then create 3 empty GameObjects in your scene (probably as children of your gun). Line these up so they point in the directions that you want your projectiles to shoot out (one with the z axis pointing forward, one angled up, one angled down). Then drag a reference of the Transform of these GameObjects to the public Transforms on your script.
Then in your script make 3 different Instantiate calls for each of your shooting directions:

Instantiate (Bulletprefab, shootDirection1.position, shootDirection1.rotation); //Do this for each shootDirection

And there you go! You should be shooting in 3 different directions! :slight_smile: