This site is currently in read-only mode during migration to a new platform.
You cannot post questions, answers or comments, as they would be lost during the migration otherwise.
0 votes

I have a simple shoot'em up in space. When enemies collide with missiles, they explode and disappear. I also send a signal (enemyHit) to HUD to update and display the score. I have declared the signal, connected it to a function in HUD, yet, the function does not get called (the 2 print methods in the function are for debugging purposes). Thanks for any help.

The missile code:

extends RigidBody2D

signal enemyHit

export (PackedScene) var Explosion

func _on_VisibilityNotifier2D_screen_exited():

func _on_Missiles_body_entered(body):

    if !body.is_in_group("player"):
        var explosion_instance = Explosion.instance()
        explosion_instance.position = get_global_position()
        $CollisionShape2D.set_deferred("disabled", true)

The HUD code:

extends CanvasLayer

var score = 0

func _ready():
    score = 0

func _on_Missiles_enemyHit():
    score += 1
    print (str(score))
    print ("function called")
    $ScoreLabel.text = str(score) 
Godot version 3.4
in Engine by (12 points)

1 Answer

0 votes

I don't see signal enemyhit being connected anywhere, and it should be somewhere in those two scripts :). And I don't think You did it in editor, because your separate missile scene propably hasn't HUD in its tree.

Another thing - You say You want to emit signal when enemy is hit, but You check if body hit by missile is in group "player" ?. Shouldn't it be "enemy" ?.

by (8,188 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.