get_slide_collision() of KinematicBody2D doesn't return X axis collisions, only Y axis collisions

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

So I have two KinematicBody2D. The player and a box that the player should be able to push. First, I coded the collision handler in the player node, and sended a value to a function on the box node, This way it worked.
But now I want to code the collision handler in the box node, so anything that push the box can move it.

When I make the collision code in the box node, only returns collisions on the Y axis, and not of the X axis (wich is what I need) When the player node collides with something, the motion of it sets to zero… I think it has to do with that, but can’t fix it.
I check the collisions, printing the collider if there is a collision with another KinematicBody2D

Any ideas? Thanks in advance!

Please show your code.

kidscancode | 2019-07-10 15:35

	for i in get_slide_count():
	   var collision = get_slide_collision(i).collider as KinematicBody2D
	   if collision:
		  print(collision)

This is in the Box node and only prints if the player is colliding on the Y axis (on top of the box) but nothing if collides on the sides.
Previously, this piece of code was on the Player node, and it worked for both axis.

chantunRey | 2019-07-10 16:21

Wouldn’t it be better if the kinematicbody collided with a rigid body instead? So instead of the box being a kinamaticbody, you make the box to rigid body and then it would easily get to be pushed. Just a suggestion

Marre | 2019-07-11 20:19