The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

So far this is my code.
My idea was that , the arrow would spawn on the archer and shoot every time I click my left mouse button.
At the moment, it only shoots once and doesn't re-spawn the arrow to shoot again.

I dont know any difficult codes but this is what i managed to write up after a bit of research.
Any suggestion, help would be much appreciated.


enter image description here

 extends Node2D

# member variables here, example:
# var a=2
# var b="textvar"

func _ready():
        # Called every time the node is added to the scene.
        # Initialization here

var speed = 800

func _fixed_process(delta):
        var arrow = load("res://scn/arrow.tscn").instance()
        translate(Vector2(delta*speed, 0))


func _input(event):
        if Input.is_mouse_button_pressed(true):


in Engine by (37 points)

1 Answer

+1 vote
Best answer

I don't see the code where you add your arrow to the scene.

var arrow = load("res://scn/arrow.tscn").instance()
add_child(arrow) # <---- missing
by (699 points)
selected by

thanks for the suggestion.
But it didn't work unfortunately.


add_child(arrow) # <---- missing

will never work

Look at this player script there is a function shoot() this creates the bullet(arrow) and shoot it.

In _fixed_process(delta) there is this check

if ( Input.is_action_pressed("shoot") ):
                if canShoot && canReload:

You don't need to turn on or off the set_fixed_process().

Thanks again for the help. I looked at your code but I wasn't sure what code I could use or add to my own project. I was looking for something simple and easy to understand.

And i found a tutorial ,
( )

This tutorial shows how to spawn objects. I found some similarities between the code thats used in your script and this tutorial. I guess the two main ones were instance() and add_child.

So I made a wall , where the arrow hits it and disappears. I also made another new node and Position2D. I connected the signal from the wall to this new node. So now whenever the arrow hits the wall, it sends the signal to make new arrows.

So my code for this new node looks like this.

 extends Node

# member variables here, example:
# var a=2
# var b="textvar"

func _ready():

export (PackedScene) var arrow

func _on_border01_body_enter( body ):
    pass # replace with function body

func create_arrow():
    print("creating arrow")
    var a = arrow.instance()
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.