godotengine / godot

Godot Engine – Multi-platform 2D and 3D game engine
https://godotengine.org
MIT License
90.58k stars 21.1k forks source link

[GodotPhysics] KinematicBody jitters against floor #49323

Open nezvers opened 3 years ago

nezvers commented 3 years ago

Godot version: 3.3.2

OS/device including version: Win 10

Issue description: Using Godot physics KinematicBody jitters up and down when walking on the ground. It seems that it's more apparent with bigger collision shapes (happens with extents 50 and not visible with 5). Behaviour points to some floating point imprecision. A character velocity approaches zero jitter gets more pronounced. Using snap enhances the jitter. Gravity doesn't influence it (enabled/disabled when grounded). Some spots on the ground are continuous even when the character is still. Bullet physics doesn't have this behavior.

https://user-images.githubusercontent.com/26794315/120857588-231a0a80-c58a-11eb-91d4-a7d168638801.mp4

Steps to reproduce: Basic KinematicBody movement, move_and_slide_with_snap, and snapping to the ground have more pronounced jitter. Floor with bigger shape (extents 50 already has hitter).

Minimal reproduction project: Godot_physics_floor_jitter.zip

Oyusi commented 3 years ago

I can confirm this issue in 3.3.2.stable with GodotPhysics, it happens with BoxShape, ConcavePolygonShape, and ConvexPolygonShape (the last 2 being created as Siblings from the Mesh dropdown of a simple CubeMesh). I've also encountered it while using a custom implementation with move_and_collide.

I have created a reproduction project more simple than the one provided by the OP. The kinematic body is already standing in a position where it jitters against BoxShape.

You can disable the floor collision shapes to test each separately, the Convex one in particular has bizarre behaviour, where it immediately teleports the KB to a corner.

3.3.2.stable kb bumpy.zip

https://user-images.githubusercontent.com/79580741/128939275-ab01e814-d7b8-42b0-adba-4294f1983cf5.mp4

fabriceci commented 3 years ago

If you don't apply gravity to the floor, there is no issue which is, I think, a good practice, because when you apply the gravity on a sloping floor, it will affect your movement. That being said, there is indeed a bug in 3.x.

However I recreated the @Oyusi 's project and there is no issue in the master (4.0).