I see you’re using the top-down shooting projectile tutorial.
From your project, I can see, you’re working on a side scroller. To adapt your code to a side scroller without changing much in your current setup, the way I would do it is to keep track of the players’ direction and pass that direction to the bullet to determine which side it will travel. This will only work for left and right bullet movement and not diagonal.
In the Player script, add:
enum _direction{LEFT = -1, RIGHT = 1}
var curretnt_direction: _direction = _direction.RIGHT #Set this to whatever direction the player faces on scene load
func _physics_process(delta):
...
#flipping sprite to the movement direction and track direction
if dir > 0:
%Sprite2D.flip_h = true
current_direction = _direction.RIGHT
elif dir < 0:
%Sprite2D.flip_h = false
current_direction = _direction.LEFT
...
func shoot():
var b = Bullet.instantiate()
owner.add_child(b)
b.direction = current_direction
In the bullet script:
extends Area2D
var speed = 750
var direction = 1 ##Set default direction of bullet
func _physics_process(delta):
position += direction * speed * delta
func _on_body_entered(body):
queue_free()
What we’re doing is essentially just to move the bullet in the direction the player was facing when it was shot.