KinematicBody returns null to try get collided Rigidbody

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

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?

:bust_in_silhouette: Reply From: Xian

Here is what I understand about those physics body.

  • KinematicBody are nodes that allow collision, collision detection, and movement.
  • StaticBody are nodes that only allow collision and collision detection.
  • RigidBody are nodes that allow collision and movements.

Each have specific uses such as StaticBody are useful for collision interact-able objects that do not need to move. Take for example stationary archery targets.
RigidBody are the opposite of StaticBody and are only used for Objects that you want to collide into, but do not register in collision. Take for example sliding doors. Sliding doors can move and you can collide into it. And sliding doors are a kind of wall or floor. And just like a wall or floor, you don’t always want the player to register a wall or floor, each time the players moves because that is wasting ram space and cause lag. Well not unless you want to make a finish like.

Now, you said you want the enemies to move, collide and register collision right? Then I recommend just changing the enemy node type to kinematicBody, it should do all what you want your enemies to do.

:bust_in_silhouette: Reply From: Adam_S

To report collisions with Rigidbodys, you need to disable infinite_inertia which is a parameter of move_and_slide() and move_and_collide().
But your player won’t be able to push Rigidbodys anymore.
So if you want them to move on a collision, you would have to apply an impulse.

Thanks, i was having the same issue and could not find this info in the documentation. I’m bad looking or it’s not there? I think it should be in the physics introduction, it is a pretty basic and important thing to know. Thanks again.

barbablanca97 | 2020-01-12 01:04