how to set projectile aiming with arrows

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By AlphaN00b

so, i set a rigidbody2d to be instanced in front of the player whenever a certain button is clicked,
problem is i want to make it spawn in different positions and shoot in different directions depending on player’s input,

here is the code i’m using for shooting:

if Input.is_action_just_pressed('shoot'):
	var projectile = PROJECTILE_SCENE.instance()
	projectile.set_position(get_position()-Vector2(-10,-5))
	get_tree().get_root().add_child(projectile)

here is the whole player code just incase:

extends KinematicBody2D

const PROJECTILE_SCENE = preload(“res://projectile.tscn”)
const UP = Vector2(0,-1)
const GRAVITY = 20
const SPEED = 200
const JUMP_HEIGHT = -500

var velocity = Vector2()

func _ready():
set_physics_process(true)

func get_input():
velocity.y += GRAVITY

if Input.is_action_just_pressed('shoot'):
	var projectile = PROJECTILE_SCENE.instance()
	projectile.set_position(get_position()-Vector2(-10,-5))
	get_tree().get_root().add_child(projectile)
if Input.is_action_pressed('ui_right'):
	velocity.x = SPEED
	$Sprite.flip_h = false
	$Sprite.play("run")
elif Input.is_action_pressed('ui_left'):
	velocity.x = -SPEED
	$Sprite.flip_h = true
	$Sprite.play("run")
else:
	velocity.x = 0
	$Sprite.play("idle")
if is_on_floor():
	if Input.is_action_just_pressed('ui_up'):
		velocity.y = JUMP_HEIGHT
else:
		$Sprite.play("jump")

func _physics_process(delta):
get_input()
velocity = move_and_slide(velocity, UP)

i thought of making other rigidbody scenes and instance them in different positions in relation to the player with different velocity depending on if the sprite is flipped for right and left + checking input for 45° angles, i think it will work but it just seem like too much of a mess.
is there a way to use only 1 instanced rigidbody scene that change position and direction according to player input or something like that?
not sure if i can’t figure it out bc i have no prior knowledge of programming or because i have the mental capacity of a chimp, either way i will greatly appreciate any help.

:bust_in_silhouette: Reply From: a human

I solved something similar by using position2d nodes. This is a somewhat crude solution, but it works.

I acually managed to get it working except for two button input(and its as messy as i expected it to be).
Not sure how position2d nodes are going to help but i’ll try it, ty.

AlphaN00b | 2020-03-22 05:52