Shoot arrow everytime mouse button is clicked

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Ninku
:warning: Old Version Published before Godot 3 was released.

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.


 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):
:bust_in_silhouette: Reply From: puppetmaster-

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

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

Ninku | 2016-08-23 12:48


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().

puppetmaster- | 2016-08-23 14:20

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()

Ninku | 2016-08-24 04:59