How to get collision/overlapping points between 2 Area2D nodes?

122 Views Asked by At

I have 2 Area2D nodes and I'm trying to find their overlapping/collision points:

enter image description here

So far I've come up with this script adapted from here:

extends Area2D


func _area_shape_entered(area_rid, area, area_shape_index, local_shape_index):
    
    var with_shape=area.shape_owner_get_shape(area_shape_index, 0)
    var self_shape=self.shape_owner_get_shape(local_shape_index, 0)
    
    var local_xform=self.shape_owner_get_owner(local_shape_index).get_global_transform()
    var shape_xform=area.shape_owner_get_owner(area_shape_index).get_global_transform()
    
    
    var contacts=self_shape.collide_and_get_contacts(local_xform, with_shape, shape_xform )
    
    print(contacts)


func _ready():
    self.connect("area_shape_entered",self,"_area_shape_entered")

But this seems to be giving me these collision points:

enter image description here

and it when I try to use 2 SegmentShape2D (as shown below) it gives me 2 collision points instead of one

enter image description here

Could someone please explain how and why this is happening? and how I can achieve the desired results?

0

There are 0 best solutions below