OK.. so I'm returning to my project after being a complete beginner when it comes to coding and
I'm trying to re-learn how my code works and how to add a new function that I was having problems
with before I quit last time .. I'm trying to figure out how to shoot up and down.

Right now, if I remember correctly all the code checks for is if the x axis of the sprite is flipped or not,
and will shoot accordingly. though I want to add to that so that when I hold W it shoots up, and when
I hold S it shoots down...

right now I'm using fireball.set_fireball_direction(1) .. and fireball.set_fireball_direction(-1)
.. but that only affects the x axis, and I cant figure out how to modify that line of code so that
it shoots up or down instead.. is there a simple line of code that allows me to modify it to switch to the y axis?
or rotate it 90 degrees or something?

  • Maybe you can introduce a Enum for the current view direction.

    #player.gd
    extends Sprite2D
    
    @export var speed: float = 100.0
    
    var fireball_scene = preload("res://Fireball.tscn")
    
    enum VIEW_DIRECTION { LEFT, RIGHT, UP, DOWN }
    
    var view_direction: VIEW_DIRECTION = VIEW_DIRECTION.RIGHT
    
    var gun_distance: float
    var gun: Node2D
    
    func _ready():
    	gun = get_node("Gun")
    	gun_distance = gun.position.x
    
    func _process(delta: float):
    	if Input.is_physical_key_pressed(KEY_W):
    		view_direction = VIEW_DIRECTION.UP
    		gun.position = Vector2(0, -gun_distance)
    	if Input.is_physical_key_pressed(KEY_A):
    		view_direction = VIEW_DIRECTION.LEFT
    		position += Vector2.LEFT * speed * delta
    		gun.position = Vector2(-gun_distance, 0)
    	if Input.is_physical_key_pressed(KEY_S):
    		view_direction = VIEW_DIRECTION.DOWN
    		gun.position = Vector2(0, gun_distance)
    	if Input.is_physical_key_pressed(KEY_D):
    		view_direction = VIEW_DIRECTION.RIGHT
    		position += Vector2.RIGHT * speed * delta
    		gun.position = Vector2(gun_distance, 0)
    
    func _input(event: InputEvent):
    	#if Input.is_action_just_pressed("M1") and is_attacking.is_stopped():
    	if event is InputEventKey and event.keycode == KEY_SPACE and event.pressed:
    			var fireball = fireball_scene.instantiate()
    			fireball.position = gun.global_position
    			match view_direction:
    				VIEW_DIRECTION.UP:
    					fireball.rotate(PI*1.5)
    				VIEW_DIRECTION.LEFT:
    					fireball.rotate(PI*1.0)
    				VIEW_DIRECTION.DOWN:
    					fireball.rotate(PI*0.5)
    				VIEW_DIRECTION.RIGHT:
    					fireball.rotate(PI*0.0)
    			get_parent().add_child(fireball)
    
    #fireball.gd
    extends Sprite2D
    
    @export var speed: float = 1000.0
    
    func _process(delta):
    	position += transform.x * speed * delta #transform.x is forward

Actually.. the gun itself is a fairy that changes position depending on how you move and
what buttons you press.. could I just add something like fairy_lock.rotate = 90 and maybe
the projectile will just adjust accordingly that way..? though I dont know what function to use.
I feel like the solution is fairly simple but I just don't know what to google look for.

I would just check if you're moving up to shoot up, and down to shoot down. If statements for shooting would have to be elif after the first one to avoid shooting in multiple directions.

    Nerdzmasterz Right.. the elif makes sense, though I want the player to be able to be stationary on the ground and still be able to hold W to shoot up so just checking for movement would not work in my case. I guess my main problem is I have no idea how to adjust my code so it just
    doesn't only affect the x axis..

    like if I just could figure out how to have the code as it is right now, but when the player faces right, it shoots up, and when the player faces left it shoots down, if I can just understand how to do that I could probably get the code working the way I want after that.

    So it would be something like
    if Input.is_action_pressed("up"):

    Then all the elif functions.

    Maybe you can introduce a Enum for the current view direction.

    #player.gd
    extends Sprite2D
    
    @export var speed: float = 100.0
    
    var fireball_scene = preload("res://Fireball.tscn")
    
    enum VIEW_DIRECTION { LEFT, RIGHT, UP, DOWN }
    
    var view_direction: VIEW_DIRECTION = VIEW_DIRECTION.RIGHT
    
    var gun_distance: float
    var gun: Node2D
    
    func _ready():
    	gun = get_node("Gun")
    	gun_distance = gun.position.x
    
    func _process(delta: float):
    	if Input.is_physical_key_pressed(KEY_W):
    		view_direction = VIEW_DIRECTION.UP
    		gun.position = Vector2(0, -gun_distance)
    	if Input.is_physical_key_pressed(KEY_A):
    		view_direction = VIEW_DIRECTION.LEFT
    		position += Vector2.LEFT * speed * delta
    		gun.position = Vector2(-gun_distance, 0)
    	if Input.is_physical_key_pressed(KEY_S):
    		view_direction = VIEW_DIRECTION.DOWN
    		gun.position = Vector2(0, gun_distance)
    	if Input.is_physical_key_pressed(KEY_D):
    		view_direction = VIEW_DIRECTION.RIGHT
    		position += Vector2.RIGHT * speed * delta
    		gun.position = Vector2(gun_distance, 0)
    
    func _input(event: InputEvent):
    	#if Input.is_action_just_pressed("M1") and is_attacking.is_stopped():
    	if event is InputEventKey and event.keycode == KEY_SPACE and event.pressed:
    			var fireball = fireball_scene.instantiate()
    			fireball.position = gun.global_position
    			match view_direction:
    				VIEW_DIRECTION.UP:
    					fireball.rotate(PI*1.5)
    				VIEW_DIRECTION.LEFT:
    					fireball.rotate(PI*1.0)
    				VIEW_DIRECTION.DOWN:
    					fireball.rotate(PI*0.5)
    				VIEW_DIRECTION.RIGHT:
    					fireball.rotate(PI*0.0)
    			get_parent().add_child(fireball)
    
    #fireball.gd
    extends Sprite2D
    
    @export var speed: float = 1000.0
    
    func _process(delta):
    	position += transform.x * speed * delta #transform.x is forward

      antonWetzel oh man, thank you so much, that might do the trick.. this is proving harder then I thought it would.. maybe its just because of the way I made shooting work in the first place.. I've been trying to just follow tutorials showing how to shoot up and down but it has proven harder to implement to my current code then expected.

        mrtapas I checked the code and edited it into full files (Godot 4.0), the only major edit is the rotation. rotate expects the angle in radians.

          antonWetzel mate, that is incredibly helpful, thank you so much, I think this might be what I've been looking for! thanks again, you are a legend.