–1 vote

I have this code. It worked in a prior attempt at this project. The projectile fired fine. Now it appears, but doesn't move. My print() statement does not print on spawn (_ready).



func _process(delta):

    # Rotate with mouse
    var mousepos = get_local_mouse_position()
    rotation += mousepos.angle()

    #Listen for mouse click and shoot
    if  Input.is_action_pressed("Click"):
        if $Timer.is_stopped(): 

func shoot():
    var a = arrow.instance()
    a.transform = $loadspot.global_transform


extends Area2D

var speed = 999
var target
var canhit = true

func _ready():
    print ("Arrow created: ", speed)

func _process(delta):
    position -= transform.y * speed * delta
    if position.y <= Globals.TOP:
Godot version 3.4.2 Stable
in Engine by (11 points)

How is the arrow reference set in the Player script? Are you sure it's referencing the Arrow script you posted?

It's not and it wasn't when it was working.
Player tree is:

 - Sprite
 - Position2D
 - CollisionShape2D
 - Timer

I changed the root Arrow node from an Area2D to a Node2D and made the Area2D part of its tree. Seemed to do the job.
Not sure why it was working on my first attempt and not here, though.

Reason I redid it: I had placed my main tscn in the autoloader and got hit with that double _ready() bug.

I guess I'm set now. But thianks!

Please log in or register to answer this question.

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.