0 votes

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.

in Engine by (19 points)

1 Answer

+1 vote

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)
by (751 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.