Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Collision detection between moving kinematic and rigid bodies is broken #46653

Closed
Tracked by #45333
e344fde6bf opened this issue Mar 4, 2021 · 4 comments
Closed
Tracked by #45333

Comments

@e344fde6bf
Copy link
Contributor

Godot version:
3.2.3.stable

OS/device including version:
N/A

Issue description:

Collision detection between a moving rigid body and a kinematic body that uses move_and_collide() will fail to detect a collision if they both move towards the same position on the same frame. See also #46601 for collision detection between two moving kinematic bodies.

Steps to reproduce:

  • Create a rigid body that will move towards the origin at 1 unit per a frame (vel=60 at 60Hz physics loop). Position it at x=-60 so at the end of physics frame 60 it will be positioned at the origin.
  • Create a kinematic body that is positioned next to the origin. On frame 60 use move_and_collide() such that it will overlap the rigid body at the origin.
  • Notice that no collision is detected by the kinematic body, and the rigid body does not react to the kinematic body and ends up overlapping it.

rigid-kinematic-collision

Minimal reproduction project:

test-rigid-kinematic-collision.zip

@Calinou
Copy link
Member

Calinou commented Mar 4, 2021

I can confirm this on 3.2 08898e9 with both Bullet (MRP default) and GodotPhysics.

Bullet

image

GodotPhysics

image

@madmiraal
Copy link
Contributor

Related to #30481 which is the same problem with two KinematicBodies.

@e344fde6bf
Copy link
Contributor Author

I don't think this is a bug after all, instead it's a result of the update order of rigid bodies.

  1. Rigid body positions updated
  2. _physics_process() called for nodes

So rigid bodies _physics_process() essential operates on a 1-frame delay. So in the example provided, the kinematic body moves on frame n and sees no collision (because the rigid body is not there yet). The rigid body is stopped on frame n+1 and since its position gets updated at the start of the frame before _physics_process() is called, that's why it ends up being stopped on the kinematic body without the kinematic body seeing a collision.

@Calinou
Copy link
Member

Calinou commented Apr 4, 2021

@e344fde6bf If this could be better documented, feel free to point out places in the manual or class reference where this could be done 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants