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

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.

in Engine by (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.

    _on_Area2D_body_entered(body):
        if body.has_method("is_ghost"):
            die()
    
  • 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"):
          die()
      
    • 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"):
              die()
              break
      
by (3,938 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.