godotengine / godot

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

CharacterBody3D - Sliding against walls with move_and_slide() becomes sticky/gritty when on floor #85971

Open Oktayey opened 10 months ago

Oktayey commented 10 months ago

Tested versions

System information

Godot v4.2.1.rc1 - Windows 10.0.19045 - Vulkan (Mobile) - dedicated NVIDIA GeForce GTX 1060 6GB (NVIDIA; 31.0.15.3623) - Intel(R) Core(TM) i5-4590 CPU @ 3.30GHz (4 Threads)

Issue description

CharacterBody3D's move_and_slide() method behaves improperly when sliding against walls while grounded. With both GDPhysics and JoltPhysics, when the body is accelerated toward a wall at an angle while it's floating and no gravity is applied, it slides smoothly and consistently. However:

With GDPhysics: If it's on the floor and accelerated toward a wall at an angle while no gravity is applied to it, its velocity becomes inconsistent while sliding, with it increasing on some frames but decreasing on others.

If it's on the floor and accelerated toward the wall at an angle while gravity is applied to it (as it'd be in reality), the sliding becomes "sticky", where it briefly stops at points along the wall that seem random, yet are consistent between tests.

With JoltPhysics: If the body is on the floor and accelerated toward a wall at an angle while no gravity is applied to it, it appears to slide against the wall pretty smoothly, but it seems to get an unusual burst of speed when it leaves the end of the wall. This 'slingshot' is even more forceful with the gravity applied.

Steps to reproduce

Apply a constant force to a grounded CharacterBody3D toward a wall at an angle to its path. This is included in the attached project, and you can comment and un-comment the included gravity applicators to test the following conditions:

Minimal reproduction project (MRP)

Move_and_slide_issue2.zip NOTE: I needed to remove the 'addons' folder containing JoltPhysics to meet the file size limit! Please install it separately if you intend to test it with Jolt.

Oktayey commented 8 months ago

In my project this happens only with the CapsuleShape3D. If i use a CylinderShape3D the jitter stops. This info might be helpful finding the bug.

Hm. From my testing, it seems that while the acceleration remains inconsistent with CylinderShape3D, it doesn't 'stick' like BoxShape3D or CapsuleShape3D when gravity is constantly applied.

Oktayey commented 8 months ago

In my project this happens only with the CapsuleShape3D. If i use a CylinderShape3D the jitter stops. This info might be helpful finding the bug.

Hm. From my testing, it seems that while the acceleration remains inconsistent with CylinderShape3D, it doesn't 'stick' like BoxShape3D or CapsuleShape3D when gravity is constantly applied.

My jitter on the CapsuleShape3D stopped when i downscaled the surface it stood on. The mesh was upscaled on the node and not the shape. So downscaling the CSGMesh (PlaneMesh) solved my problem.

Wait, so you solved your problem by setting the scale of your ground's CollisionShape3D's Node3D object to 1x and instead setting the dimensions of its collision shape? Am I understanding correctly? Because the scale of my ground's CollisionShape3D's Node3D object has always been unchanged; it's 1x on all axes, and the issue still occurs with BoxShape3D and CapsuleShape3D.

Here's my project file: Freshslidetest.zip