Top down shooting direction determined by the direction, the player is facing

Hello, I want my character to shoot in the direction he is facing. I’ve so far learned about shooting upwards(refering to the space shooter tutorial in the Udemy course) and enemies shooting downwards.
I’ve also heard seen tutorials on how to fire bullets determined by the mouse position.
I however, just want to make the player shoot in the same direction, that he is facing, meaning that if he is facing rigth, he will shoot to the rigth, facing left fires bullets to the left etc.
I’m not planning on using any mouse position.

This is the code for firing the bullet. The firePoint is a transform object hidden as a child of the player.

 if (Input.GetKeyDown(KeyCode.X))
        {
            if (canShoot)
            {
                shoot();
            
            }

           

        }
        
        
    }

    private void shoot()
    {
        GameObject mySunBall = Instantiate(sunBall, firePoint.position, firePoint.rotation);
        Rigidbody2D rb = mySunBall.GetComponent<Rigidbody2D>();
        rb.AddForce(firePoint.up * fireForce, ForceMode2D.Impulse);
    }

I know the solution is linked to these 3 bottom lines. At the moment, the player only shoots upwards regardless of the direction he is facing.

1 Like

Not 100% sure if this was a question because your code works just fine.
ezgif-2-2bde91e6b1b8

But if you are having issues and it’s not working, it has something to do with how you are dealing with rotation.