From the RayCast2D class documentation:
bool collide_with_areas [default: false]
set_collide_with_areas(value) setter
is_collide_with_areas_enabled() getter
If true, collision with Area2Ds will be reported.
You're using collide_with_areas
as though it indicates whether the raycast is currently colliding with areas, while in truth it is a class property denoting whether the raycast should report collisions with areas at all.
Instead, you should be setting collide_with_areas
(and enabled
!) to true (either through the inspector, or via code) and then calling raycast.get_collider()
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…