0 votes

Player is a KinematicBody and enemy is a Rigidbody. I'm using moveandslide() 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 moveandcollide() 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?

in Engine by (139 points)

2 Answers

+2 votes
Best answer

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.

by (1,468 points)
selected by

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.

0 votes

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.

by (271 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.