2D Shooting right only. Doesn't flip direction with character

Hi,

My situation is that I have a 2D platformer. The shooting works, but only towards the right direction. I have attached the script to a empty game object to position the shooting position exactly to where I want. I have tried several ways; trying to add another direction and trying to flip the child, all which I couldn’t do.

I have 3 different scripts that I use to do this…

My First:

public class InfitityMovement : MonoBehaviour {

	public Vector2 speed = new Vector2(10, 10);

	public Vector2 direction = new Vector2(-1, 0);
	private Vector2 movement;

	
	// Update is called once per frame
	void Update () {
		movement = new Vector2(
			speed.x * direction.x,
			speed.y * direction.y);
	
	}

	void FixedUpdate()
	{
		// Apply movement to the rigidbody
		rigidbody2D.velocity = movement;
	}
}

The Second:

public class PlayerShooting : MonoBehaviour {
	
	public Transform bullet;

	public float shootingRate = 0.25f;

	private float shootCooldown;
	
	void Start()
	{
		shootCooldown = 0f;
	}
	
	void Update()
	{
		if (shootCooldown > 0)
		{
			shootCooldown -= Time.deltaTime;
		}
	}

	public void Attack(bool isEnemy)
	{
		if (CanAttack)
		{
			shootCooldown = shootingRate;
			
			// Create a new shot
			var shotTransform = Instantiate(bullet) as Transform;
			
			// Assign position
			shotTransform.position = transform.position;
			
			// The is enemy property
			ShootingControl shot = shotTransform.gameObject.GetComponent<ShootingControl>();
			if (shot != null)
			{
				shot.isEnemyShot = isEnemy;
			}
			
			// Make the weapon shot always towards it
			InfitityMovement move = shotTransform.gameObject.GetComponent<InfitityMovement>();
			if (move != null)
			{
				move.direction = this.transform.right; // towards in 2D space is the right of the sprite
			}
		}
	}

	public bool CanAttack
	{
		get
		{
			return shootCooldown <= 0f;
		}
	}
}

Lastly…

public class ShootingControl : MonoBehaviour {

	public int damage = 1;

	public bool isEnemyShot = false;

	// Use this for initialization
	void Start () {
		Destroy (gameObject, 10);
	
	}
}

I have tried playing around with the transform.right section, didn’t work. I tried changing the Vector2 direction variable to different numbers, didn’t work. Ive just been clueless all day!

if you attached it to an empty GameObject, then I think I see your problem. When you tell things to go to the right or left of an object, they go to the right or left of the object. I think your problem is that you are shooting from a different point. The wrong point. I have 3 ideas for you: 1. make the E.G.O. (empty gameobject) a child of your player. 2. put the script in the character, not the E.G.O. 3. make the script flip whenever the player flips, by making the left arrow key not just move, but rotate the shooter as well. Hope this works!