2D Weapon Rotation Behaviour Changes on Flipping Sprite?

Hi,

I have a player and that object has a weapon. The weapon can be rotated when it’s a crossbow. So the player can aim and shoot. I’ve noticed when I face left, aim with weapon and then shoot, the projectile seems to shoot in the opposite direction it’d go, as opposed to facing right (where the project shoots in the direction you expect)

I use something like this for rotating,

if(input.y >= 0.1f)
{
			myTransform.Rotate (Vector3.forward * 8);//-90);
			crossBowAngle = this.gameObject.transform.eulerAngles;
}

if(input.y <= -0.1f)
{
			myTransform.Rotate (Vector3.forward * -8);//-90);
			crossBowAngle = this.gameObject.transform.eulerAngles;
}

This code seems to work as intended and is based on the weapon obj which is a separate obj/script to the projectile.

The projectile simply has,

		if(dirRight)
		{
			if(flipped)
			{
				Flip();
				flipped = false;
			}

			velocity.x = Time.deltaTime * speed;
		}
		else
		{
			if(!flipped)
			{
				Flip();
				flipped = true;
			}

			velocity.x = -(Time.deltaTime * speed);
		}

		myTransform.Translate(velocity);

The flipping here is just to ensure the projectile sprite doesn’t appear to be shot out backwards.

I believe the problem lays within my actual player script where, if i face left or right, I flip the player using the following,

	private void Flip()
	{

		//Flip the sprite to face the correct direction accordingly.
		playerState.facingRight = !playerState.facingRight;
		Vector3 theScale = myTransform.localScale;
		theScale.x *= -1;
		myTransform.localScale = theScale;


		GameManager.playerDirRight = playerState.facingRight;
		
	}

Any ideas? So just to make it clear, when facing right, if i aim up or down and then shoot, the projectile will shoot just fine if the direction as expected.

When facing left however, if i aim up, you can expect the projectile to be shot down instead. If i aim down, it will be shot up. Can anyone see anything in the code i provided that may be causing this issue? Thank you in advance

Ok I got it. Due to flipping the rotation was some what flipped. Studying the values of the projectiles in the inspector, I noticed if i applied a negative to the value of the z rotation, it’d go in the desired direction (when facing left,which was the problem here).

Below code fixed it for me (probably a little hacky but it works)

	void OnEnable()
	{
		dirRight = GameManager.playerDirRight;

		if(!dirRight)
		{
			myTransform = this.transform;
			Vector3 angle = myTransform.rotation.eulerAngles;
			angle.z = -angle.z;
			Quaternion q = myTransform.rotation;
			q.eulerAngles = angle;
			myTransform.rotation = q;

		}
	}

It’s in OnEnable() because of obj pooling.