body_entered not triggering for my Area2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By l0stwoods

Hi! I’m new to the engine and am having trouble getting a teleporter I have set up triggering. I have a KinematicBody2D (my player) and an Area2D (the teleporter) set up in the same scene. I have this code put on the teleporter:

extends Area2D

func _on_teleporter_r_body_entered(body):

    if "ch_p1" in
    	print(str('Player has entered'))

Neither the error message nor the teleportation function (tp_r) trigger when I enter the Area2D. I’ve tried alternatives like area_entered and that didn’t work either, and my KinematicBody2D has no trouble colliding with the ground I have set up. They are all on the same collision layer. Is there some piece I’m missing along the way? Here are my node trees for everything relevant:


Thank you!

  1. Have you set up a collision shape for all the nodes requiring it? All CollsionShapes need… well, a shape.

  2. This body.tp_r should be body.tp_r(). It would normally throw an error message, but you never know.

  3. Are you sure this “ch_p1” is part of the string you are checking? Maybe you would like to print something when the collsion occurs just to see if the Area2D is detecting collisions?

johnygames | 2020-01-04 23:26

The CollisionShape2Ds definitely have shapes, so that isn’t the issue. I noticed the missing parenthesis just before you responded. Interestingly, it never gave me an error message for those. I fixed it anyways but nothing changed.
I have in the code I posted an error message but it has never once shown up, so the objects are probably not colliding. I just can’t figure out why.

l0stwoods | 2020-01-04 23:48

So, let me get this straight, have you tried this?

extends Area2D

func _on_teleporter_r_body_entered(body):

It is important that you rule out the possibility that the Area2D is not detecting collisions.

johnygames | 2020-01-05 00:42