How do i shoot an arrow in the direction of the player when i press the spacebar key for a 2D top down game?

I want to make a way to shoot an arrow when i press the space bar in the direction my player is facing and make it disappear when it collides with something for a 2D top down game. How do i do this?

I dont want the character to shoot in the direction of mouse just where the sprite is facing

Coppy of previous question as i forgot to add the 2d part

you just need to :

  • -Create an arrow prefab with a rigidbody2D and a collider2D attached
    to it.

  • -Attach a script to your player object that will handle shooting the
    arrow.

  • -In the script, create a public variable to hold the arrow prefab.

  • -In the Update method of the script, check if the spacebar is pressed.

  • -If the spacebar is pressed, create an instance of the arrow prefab using
    the Instantiate method.

  • -Set the position of the arrow to the position of the player.

  • -Set the velocity of the arrow’s rigidbody2D component to a vector
    pointing in the direction the player
    is facing.

  • -To make the arrow disappear when it collides with something, add a script
    to the arrow prefab that will detect collisions with other objects.

  • -In the collision detection script, destroy the arrow game object when it
    collides with something.