Is this what you want to try to achieve? https://imgur.com/a/j0pUFUZ
If it's the case, you can measure the angle between player and mouse to determine which way they are facing. Then set the animation accordingly
func _process(delta):
var angle_to_mouse = global_position.angle_to_point(get_global_mouse_position())
angle_to_mouse = rad2deg(angle_to_mouse)
angle_to_mouse = wrapf(angle_to_mouse, 0, 360)
if angle_to_mouse < 45 or angle_to_mouse >= 315:
animation = "left"
elif angle_to_mouse >= 45 and angle_to_mouse < 135:
animation = "up"
elif angle_to_mouse >= 135 and angle_to_mouse < 225:
animation = "right"
else:
animation = "down"
Then for the bullet, you can check which direction the character is facing, and set the direction vector to the bullet on instancing it.
func shoot():
var bullet = bullet_scene.instance()
bullet.global_position = global_position
match animation:
"left":
bullet.dir = Vector2.LEFT
"right":
bullet.dir = Vector2.RIGHT
"down":
bullet.dir = Vector2.DOWN
"up":
bullet.dir = Vector2.UP
get_tree().current_scene.add_child(bullet)
And here's the bullet script
extends Sprite
var dir: Vector2
func _physics_process(delta):
position += dir * 10