Contact with CollisionShape2D breaks collision with Kinematic body

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

When my player object (kinematic body) is in contact with the barriers I set up (collisionShape2D nodes), it screws up the collision with enemy mobs and stops them from despawning on contact. This is my first project and I have no clue what could be causing this.

This is my collision code on my player node:

var collision_check = move_and_collide(motion * delta)
# Check for collision with enemies
if collision_check != null && collision_check.collider.is_in_group("Targets"):
	take_damage(self, collision_check.collider.contact_damage)

VIdeo of bug

:bust_in_silhouette: Reply From: MaaaxiKing

Make the barriers of type StaticBody2D and add CollisionShape2D as a child to them.

That didn’t solve the issue unfortunately. Forgot to mention that the nodes were children of a rigidbody, testing with a staticbody as a parent didn’t change anything.

TheJollyReaper | 2020-06-19 16:22

Oh no, the player is one scene and the barrier is one too. Then you instance them both in one world scene.

MaaaxiKing | 2020-06-19 16:26

Created the barrier in a separate scene and instanced it just now, still didn’t work. Same behavior :confused:

I’m reading through a reddit post, and it sounds like move_and_collide() only returns one of the colliding objects at a time, which could explain what issue i’m having. Trying to find an alternate way of checking for collisions to see if it helps

TheJollyReaper | 2020-06-19 16:34

:bust_in_silhouette: Reply From: TheJollyReaper

For any interested, added collision check to enemy objects, replaced player movement and collision detection (move and collide) with move and slide. Seems to have fixed all the collision issues i was having.