0
\$\begingroup\$

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?

\$\endgroup\$
1
\$\begingroup\$

You need to pass false for the infinite_inertia parameter of move_and_collide. From the docs:

If infinite_inertia is true, body will be able to push RigidBody nodes, but it won’t also detect any collisions with them. If false, it will interact with RigidBody nodes like with StaticBody.

\$\endgroup\$
1
  • \$\begingroup\$ Thanks, it works. \$\endgroup\$
    – modernator
    Nov 5 '19 at 13:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.