There's a couple ways, but it's not as easy as the signals in the KinematicBody2D node unfortunately. If you are using move_and_collide
, it will return collision data when the function is called.
If you are using move_and_slide
, then you can get the collision data using either get_last_slide_collision or get_slide_collision. What makes it a little more tricky is that if you have a character that slides on the floor and hits a wall, that will be 2
slide collisions and get_last_slide_collision
will only return the last one (likely the wall).
All three of the functions will return a KinematicCollision2D object, which then you can get the collider from for comparing.