Player is a KinematicBody and enemy is a Rigidbody. I'm using move_and_slide() to move player. When they collided, each both push them opposite direction, so it seems like physics stuffs working, however when I try to get collided object, it always returns null.

Using move_and_collide() returns null, and try this way also returns null:

for index in get_slide_count():
    var collision = get_slide_collision(index)
    print(collision)

However when I changed the type of enemy to StaticBody, now it gives me enemy. But I don't want to use StaticBody to enemy, they needed to move! Why get collided is always null even it's collided with Rigidbody?

Out of curiosity, do you get the same results if you use move_and_collide? I wonder if the issue is the sliding itself is causing the event with the RigidBody to be dropped. If the sliding is causing the issue then it is likely a bug, but knowing whether move_and_collide works could help narrow what is causing the bug.

Are you looking for slide collisions after or before calling move_and_slide? According to the documentation, get_slide_count and get_slide_collision only update after move_and_slide is called. I don’t know if that would make a difference or not, but it might be something to test.


After doing some research, I found this GitHub issue. The last comment in the issue mentions that the documentation states that if you have infinite_inertia set to true, then move_and_slide will not detect collisions. That might be causing the issue. I would look to see if changing infinite_inertia has any effect.

@TwistedTwigleg Thanks, as you like said, set infinite_inertia to true, now it works.

3 years later