If you want to check if the Area2D
is positioned correctly during runtime enable Debug -> Visible Collision Shapes.
If you want to check if _on_Area2D_area_entered
is running, add breakpoints (or use print).
Did you get an error?
If there isn't a Node
there, this expression will cause an error in runtime:
get_parent().get_node("Level 1/Area2D/Flag")
If you want to be able to check, you can use get_node_or_null
and is_instance_valid
.
Since you didn't mention any error, I'm going to guess the method is not running.
If the method is not running, the most likely culprit is that - I'm guessing given then name of the method - you connected the "area_entered"
signal but intended to connect the "body_entered"
signal.
The "area_entered"
signal will trigger when another Area2D
enters the Area2D
. But I only see one Area2D
in your scene tree. On the other hand the "body_entered"
will trigger when a PhysicsBody2D
(e.g StaticBody2D
, KinematicBody2D
, RigidBody2D
) enters the Area2D
. In either case you get what entered as a parameter of the method.
Other reasons why the Area2D
might not be detecting what you want include no intersection of collision_layer
and collision_mask
and monitoring
being disabled.
And to dismiss a couple possible misconceptions:
- The
"area_entered"
and "body_entered"
trigger when the Area2D
or PhysicsBody2D
respectively enter the Area2D
, not every frame they are inside. So rotation_degrees += 1
is not a rotation animation.
- You will get notifications of anything that trigger the signals, not just the object to which you connected it. You may have to further filter, e.g.
if body == self:
.
For people arriving here from search, I want to link a similar case: Enemy is not affected by bullets. And also my full explanation of how to set up physic nodes.