How to detect overlap between 2 KinematicBody2D

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By elahehab

I have multiple KinematicBody2Ds moving in the game screen randomly. I want these bodies to overlap and move and then stop slowly. But I dont want them to overlap when they stopped. So I want to check if they have any overlap they continue moving. The problem is I cant find any way to check overlap or find overlapping bodies!
This is my node structure:
KinematicBody2D

  • Sprite
  • CollisionPolygon2D

When I use collisionPolygon my bodies do not overlap. So I disabled collisionPolygons.
All of these bodies are child of an area2D node. I tried using get_overlapping_bodies but it always returns 0 object.
I’m just so much confused! Can someone explains what should I do?

:bust_in_silhouette: Reply From: whiteshampoo

You can use an Area2D.

it has a signal area_entered
or you can also use the method get_overlapping_areas.

I used moving functionalities of kinematicBody2D like move_and_slide. Does area2D have similar functionalities?
Isn’t there a method to detect overlap between 2 kinematicBody2D?!

elahehab | 2020-11-04 19:51

You can put the bodies that should not collide but overlap into different collisionlayers(/masks) and just add the area2D as a child to you kinematicbody2d, so it will move with it :slight_smile:

whiteshampoo | 2020-11-05 06:31

This method works :))
Thanks a lot.
Solved my issue.

elahehab | 2020-11-08 07:30