I’ve got a CharacterBody2D thats meant to just slide to the left when playing and stop when paused. The movement works fine, but I have a few Area2D nodes, two within my base script alongside the CharacterBody2D, and one as a child of a Panel node in my base script. All three Area2D nodes can detect mouse_entered / mouse_exited. All three Area2D nodes and the CharacterBody2D node are set to collision layer/mask 3. Does anyone know why the Area2D nodes are not detecting when the CharacterBody2D node enters? Thank you!
#CharacterBody2D movement code
func _play():
velocity = velocity.lerp(Vector2(1.0, 0.0).normalized() * speed, accel)
func _pause():
velocity = velocity.lerp(Vector2.ZERO, fric)
func _physics_process(_delta: float) -> void:
move_and_slide()
#one of my Area2D nodes - the CharacterBody2D is in the group "line"
func _on_end_measure_body_entered(body: Node2D) -> void:
if body.is_in_group("line"):
movingLine.position = Vector2(59.0, -147.0) #this line will not trigger
Is the Area2D a thin barline?, and/or is the body moving relatively fast? Wondering if the collision gets missed because the physics sample rate is too low to catch the collision consistently.
Is the body actually in group “line”?
I would put a breakpoint on the if statement and see if it is accidentally filtering out the body.
Also check that the area monitoring is set to true.
I don’t see a problem in anything that you’ve already posted, so I’m guessing the problem is elsewhere.
Would this print statement fire?
#one of my Area2D nodes - the CharacterBody2D is in the group "line"
func _on_end_measure_body_entered(body: Node2D) -> void:
print("Triggered!") # Will this fire?
if body.is_in_group("line"):
movingLine.position = Vector2(59.0, -147.0)
Are you sure you have set all the layers and masks properly? Could you double-check?