Ah, thanks. It looks like in my case, the KinematicCollision2D.normal
member is probably more useful, since I only really care about whether the player is colliding to the left or to the right. But using KinematicBody2D.get_slide_collision
definitely seems like the way to go. I'll also have to loop through each index, from 0
to KinematicBody2D.get_slide_count
, and check the normal of each collision until I find one with a non-zero x
component, but that should be easy enough.
Thanks!
Edit: For completion's sake, here's the helper function I came up with:
func get_which_wall_collided():
for i in range(get_slide_count()):
var collision = get_slide_collision(i)
if collision.normal.x > 0:
return "left"
elif collision.normal.x < 0:
return "right"
return "none"