2D bullet angle question. Please Help.

I’m trying to make a 2D sidescroller with shooting, where moving the mouse up and down moves the gun the player is holding but only until a certain height (similar to the game metal slug.) The player has an invisible object “the shoulder” as a child, this is what rotates upa dn down. The gun is a child of this and is slightly in front of it. The bullets shoot forward from the gun. The player has a texture flip script on him, this makes him and all his children flip over. Everything works perfectly fine on the initial direction the character starts in, however wen he moves the other way, the gun rotates fine, but the bullets shoot downwards more as I move the gun up and upwards more as I move the gun down. I have searched all over my script and tried many things to fix this. I am fairly new to unity and scripting. Please help.

This is the initial way he is facing, debugged using raycast…

This is the opposite way…

var X : float;
var right : boolean;

function Start () {
	//Gathering normal object scale 
	X = transform.localScale.x;
}

function FixedUpdate () {
	if(Input.GetKey('a')){
		right = false;
		}
		
 	
	if(Input.GetKey('d')){
		right = true;
		}
 	
 	if(right == true){	
 		transform.localScale.x = -X;
 		}
 	else{
 	transform.localScale.x = X;
 	}
}

Texture Flip Script, JavaScript

public class Fire : MonoBehaviour {

	public GameObject BulletPrefab;

	void Start () {
	
	}

	void Update () {
		if(Input.GetMouseButtonDown(0)){
			Instantiate(BulletPrefab, transform.position, transform.rotation);
		}
	}
}

Fire Projectile Script, C#

public class MouseLook : MonoBehaviour {
	
	public float sensitivityY = 15F;
	public float minimumY = -60F;
	public float maximumY = 60F;
	public bool right = true;
	
	float rotationY = 0F;
	
	Quaternion originalRotation;
	
	void Update ()
	{
		if(Input.GetKey("a")){
			right = false;
		}
		if(Input.GetKey ("d")){
			right = true;
		}
	

		if(right == false){
			rotationY += Input.GetAxis("Mouse Y") * -sensitivityY;
		
			rotationY = ClampAngle (rotationY, minimumY, maximumY);
		
			Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
		
			transform.localRotation = originalRotation * yQuaternion;
		}
		if(right == true){
			rotationY += Input.GetAxis("Mouse Y") * -sensitivityY;
			
			rotationY = ClampAngle (rotationY, minimumY, maximumY);
			
			Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);
			
			transform.localRotation = originalRotation * yQuaternion;
		}
	}
	void Start ()
	{
		if (rigidbody)
			rigidbody.freezeRotation = true;
		originalRotation = transform.localRotation;
	}
	
	public static float ClampAngle (float angle, float min, float max)
	{
		if (angle < -360F)
			angle += 360F;
		if (angle > 360F)
			angle -= 360F;
		return Mathf.Clamp (angle, min, max);
	}
	}

Modified Version of MouseLook script this makes the gun move with the mouse but only to a certain height, C#

ublic class Projectile : MonoBehaviour {

	public float ProjectileSpeed;
	public bool right;

	private MouseLook shoulder;


	void Start () {
		shoulder = GameObject.FindGameObjectWithTag("shoulder").GetComponent<MouseLook>();
	
		if(shoulder.right == true){
			right = true;
		}

		if(shoulder.right == false){
			right = false;
		}
	}

	void Update () {

		if(right == true){

			float amountToMove = ProjectileSpeed * Time.deltaTime;
			transform.Translate(Vector3.forward * amountToMove);
		}
	
		if(right == false){

			float amountToMove = ProjectileSpeed * Time.deltaTime;
			transform.Translate(-Vector3.forward * amountToMove);
		}


	}
}

Projectile Script that fires the bullet prefab, C#

In the unity editor you could always attach the bullet to the gun which rotates I believe, this would mean when it is instantiate as a copy of that object you would not have to rotate it as it will be the same rotation as the gun/hand.

(havent tested but should work)

Note: if that doesn’t work you may also have to set the point of rotation to the center of the character.

Try setting the initial direction of the bullet as the vector from the shoulder position to the gun position (normalized) and use that vector to update the bullet. That way you don’t need to worry about rotations and stuff.