See what kinnematic body is colliding with

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

Im pretty new to godot and im trying to make a game where you need to dodge giant raindrops falling from the sky, my player and raindrops are both kinnematicbody2Ds. I need the player to die if it hits a raindrop and im not sure how to detect the collision, the player is moved using “move_and_slide”

:bust_in_silhouette: Reply From: Gabriel

After the “move_and_slide” use “get_slide_count()” to get the number of collisions that occurred, “get_slide_collision()” to get a specific collision then use “.collider” to get the collider:

for i in get_slide_count():
    var collision = get_slide_collision(i)
    print("Collided with: ", collision.collider.name)

Related doc : KinematicBody2D

This worked perfectly, thank you so much! Ive spent hours trying to figure this out XD

Trey Stevens | 2019-09-30 03:27