How to detect collision between two KinematicBody2Ds?

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

I’m currently trying to create crumbling tiles for my platformer in godot. I can’t figure out how to detect the collision between the player and the platform. Any help would be appreciated.

:bust_in_silhouette: Reply From: kidscancode

A KinematicBody2D reports collisions when you move it with one of its movement methods - move_and_collide() or move_and_slide().

In the case of move_and_collide() it’s the return value:

var collision = move_and_collide(velocity*delta)

In the case of move_and_slide() it’s possible to produce more than one collision from a single movement call, so there are additional methods to handle that:

velocity = move_and_slide(velocity, Vector2.UP)
for i in get_slide_count():
    var collision = get_slide_collision(i)

In either case, you get a KinematicCollision2D object (Click here for doc), which contains all the relevant information about the collision.