Saturday, November 26, 2022
HomeGame Developmentgodot - The right way to verify which Area2D's are overlapping with...

godot – The right way to verify which Area2D’s are overlapping with KinematicBody2D?


That is a lot simpler beginning with the Area2Ds. 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)

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments