enter code here
Oh I see that is the player code not the arrow code. In that case in your arrow code you want to specify from the players code which direction the arrow is to go?
On that assumption you will need a direction var to specify so something like this
var ArrowDirection = Vector2.ZERO
then in the player code you will need a var to pass to it so a change like this:
var last_direction = Vector2.ZERO
var packed_arrow = preload("res://projectile/Arrow.tscn")
var holdArrDirection = Vector2.ZERO
func _process(delta):
var move_x = Input.get_action_strength("right") - Input.get_action_strength("left")
var move_y = Input.get_action_strength("down") - Input.get_action_strength("up")
var direction = Vector2(move_x, move_y).normalized()
if (direction != Vector2.ZERO):
last_direction = direction
if (Input.is_action_just_pressed("shoot")):
if move_x != 0:
holdArrDirection.x = move_x
elif move_y != 0:
holdArrDirection.y = move_y
var arrow = packed_arrow.instance()
arrow.global_position = global_position
arrow.rotation = last_direction.angle()
arrow.ArrowDirection = holdArrDirection
get_parent().add_child(arrow)
move_and_slide(direction * speed)
You may have to also reset the holdArrDirection somewhere in your code but this should work.