Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Turnovus |
I’m trying to create an enemy with a Area2D node. The idea is that when the player, which is a KinematicBody2D node, intersects the Area2D, the Area2D will send a signal to its parent, the enemy. However, whenever the player and enemy intersect, nothing happens. Does it have to do with the fact that both bodies are moving? I have tried using the body_enter
signal, and even gave the player its own Area2D and used the area_enter
signal. Neither method appears to work.
The Area2D node is connected to the enemy node by the following line of code in the _ready()
method:
$Area2D.connect("area_entered", self, "_on_body_entered")
And the signal connects to the following method:
func _on_body_entered():
print("stab")
emit_signal("stab")
However, as evidenced by no output being printed to the console, this method is never called.
I tried placing the following code directly into the enemy’s Area2D, but still no results:
extends Area2D
func _ready():
connect("area_entered", self, "_on_area_entered")
func _on_area_entered():
print("Test")
I also tried the above with body_entered
.
Here are the collisions:
And here are the node trees:
You need to share more details of what you’ve tried and how you have things set up. By your description, that is the way it should work, so it’s likely you’re doing something wrong. body_entered
is the correct signal. A couple of things to try:
- Have you attached a CollisionShape2D to the Area2D? It won’t work unless it has a shape defined.
- Did you connect the signal in the Inspector, or via code? If the latter, please share.
- How are you checking to see if it works?
kidscancode | 2019-08-01 23:41