Best way to implement a bullet in 2D

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

I was thinking on how to best implement a bullet function.

Suppose I have a project structure Main > Player (KinematicBody2D), and I have a Bullet (KinematicBody2D) scene waiting to be instanced.

If I want to instance a bullet, I can instance it in the Main by making the Player scene send a signal to the Main, or I can directly instance it in the Player scene without having to send a signal.

Is the other implementation better than the other? Or is there a better way to do this other than the two. I’m mostly concerned on what implementation would be the best performance-wise.

:bust_in_silhouette: Reply From: supper_raptor

I think 2nd option is better and more logical. Very basic bullet Implementation -
Player scene

onready var main_scn = get_parent() # get main scene

func on_trigger_pressed():
	var bullet = bullet_scn.instance()
	bullet.dir = dir # Set direction
	main_scn.add_child(bullet)