0 votes

Hello guys, I'm having some problem to emit a signal between 2 scene.
What I'm trying to make is that:
I'm in the first scene, and after 1 minute a character (let's call it "Ghost") will be add in the first scene. I need that Ghost if he touch the player, emit a signal in a player function (to let the character player die), but like this I don't know how to connect this.
(If it was in the same scene from the start, were simple)
Thank you for any reply, and sorry about my bad english.

asked Sep 25, 2019 in Engine by 33net21 (12 points)

1 Answer

0 votes

In this case, what can do instead is have the player detect a collision with a ghost. In your ghost's script add an empty method is_ghost so that your player can tell whether it collided with a ghost or not.

With player it depends on what type of CollisionBody it's using.

  • Area2D:
    In the editor, connect this node's body_entered(Node body) signal to itself. The function this signal is connected to is where you will test which body you "collided" with, and if it's a ghost, die.

        if body.has_method("is_ghost"):
  • KinematicBody2D:
    In the script in _physics_process you will add code to detect the body you collided with. This depends on whether your body uses,

    • move_and_collide In which case you'd do

      # replace original call to move_and_collide with this.
      if move_and_collide(your_velocity_var).collider.has_method("is_ghost"):
    • move_and_slide In which case you'd do

      # comes after call to move_and_slide
      for i in get_slide_count():
          if get_slide_collision(i).collider.has_method("is_ghost"):
answered Sep 25, 2019 by SIsilicon (3,795 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 How to use this Q&A? before posting your first questions.