That is a lot simpler beginning with the Area2D
s. You possibly can question every Area2D
with overlaps_body
. One thing like this:
var areas := [$Area, $Area2] # maybe get the record from elsewhere
for space in areas:
if space.overlaps_body(self):
print("Overlapping " + space.title)
However, if you do not have references to the areas, you’ll have to do a physics question, which I imagine could be like this:
var area := get_world_2d().direct_space_state
var question := Physics2DShapeQueryParameters.new()
question.collide_with_areas = true
question.collide_with_bodies = false
question.set_shape($CollisionShape2D.form)
question.rework = $CollisionShape2D.global_transform
var end result := area.intersect_shape(question)
for area_collision in end result:
var space := area_collision.collider as Area2D
if is_instance_valid(space): #maybe another checks right here
print("Overlapping " + space.title)