godotengine / godot

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

Cylinder shape collision issues with GodotPhysics #57048

Open elvisish opened 2 years ago

elvisish commented 2 years ago

Godot version

3.4.2

System information

Windows 7 64-bit

Issue description

A few issues with Godot Physics that aren't present if the engine is switched to Bullet.

Steps to reproduce

Here's is an example of ramp handling in this movement + upstepping controller, none of this glitching occurs with bullet:

https://user-images.githubusercontent.com/16231628/150599314-e6c72c45-ecf7-4497-a038-e9938075fa0f.mp4

Some more ramp weirdness:

https://user-images.githubusercontent.com/16231628/150600827-d5b29e23-932f-48d2-b706-0bb1145abe41.mp4

Strange edge detection (wish I hadn't hit stop cause on the last couple of frames I get stuck halfway into the ramp and cannot move):

https://user-images.githubusercontent.com/16231628/150600988-4f437dac-b86c-4fdc-8908-605166bce07c.mp4

There's other times where it'll get stuck in unusual geometry (right at the end I can't move):

https://user-images.githubusercontent.com/16231628/150601113-15075af2-cdf7-4f37-976f-1c36079f20e3.mp4

This is all fixed by using Bullet, here's my test project:

Minimal reproduction project

gp_vs_bullet.zip

elvisish commented 2 years ago

Starting to wonder if this is because of my use of cylinder colliders rather than capsule colliders, I haven't tested thoroughly yet but the problems don't seem as bad (or present?) if switching to capsules. @pouleyKetchoupp do cylinders have some issues with edge detection using Godot Physics compared to capsules?

elvisish commented 2 years ago

Here's Godot Physics getting stuck with a box collider around tight architecture (if I set the collider to not rotate with the camera, it's impossible to rotate free)

This does not happen with Bullet.

https://user-images.githubusercontent.com/16231628/150786371-afc36501-9ddd-4dfa-a8a4-9a1063bf45a4.mp4

boxcollider_test.zip

Calinou commented 2 years ago

Here's Godot Physics getting stuck with a box collider around tight architecture (if I set the collider to not rotate with the camera, it's impossible to rotate free)

What do you mean? When using a box collider for a character, you should never rotate this collider (effectively treating it as an AABB). Instead, you should rotate the camera only. This is how all games that use AABB-based colliders handle things (id Tech, Source, …) :slightly_smiling_face:

elvisish commented 2 years ago

Here's Godot Physics getting stuck with a box collider around tight architecture (if I set the collider to not rotate with the camera, it's impossible to rotate free)

What do you mean? When using a box collider for a character, you should never rotate this collider (effectively treating it as an AABB). Instead, you should rotate the camera only. This is how all games that use AABB-based colliders handle things (id Tech, Source, …) slightly_smiling_face

Yep, I'm not rotating the collider for those very reasons, I was just saying that if I do rotate the collider, I can actually loosen the body and move freely whereas with fixed rotation it gets stuck indefinitely, ironically enough.

jitspoe commented 2 years ago

I'm also experiencing these issues, but they seem even more pronounced with Godot 4. I end up teleporting all over the place if I try to move up even a gradual slope with a cylinder collider. Capsule is better, but even the capsule collider gets stuck against geometry (easiest repro is have 2 convex hulls 1m apart and have a 1m diameter capsule or cylinder and you will just get stuck permanently if you try to go between them). Collision behaves a bit better using box shapes, but I need convex hulls for more complex level geometry.

timshannon commented 2 years ago

FWIW, in GD4 I noticed the same issue (even more pronounced) where a basic character body (cylinder, or capsule) couldn't even walk over low terrain, and I work around it by implementing something similar to smooth stepping (https://github.com/mrezai/GodotStairs) with physics collision checks to test if the body can "step up" or not.

fabriceci commented 2 years ago

There are known problems with cylinders at the moment, like #57476

@jitspoe Could you provide a minimal reproduction project in 4.0 without, if possible, using cylinder shapes? (to avoid mixing issues)

@timshannon The handling of stairs is left to the user (at least for now), if your capsule hits the ground with an angle greater than the floor_max_angle, you will be effectively stopped. If this is not what happened, same thing, could you please provide a minimal reproduction project?

jitspoe commented 2 years ago

@fabriceci Yeah, here's pretty much the simplest example of getting stuck. Just use the arrow keys to move between the 2 boxes and note that sometimes you can't move back out. test_capsule_stuck.zip

fabriceci commented 2 years ago

@elvisish Have you tried with Godot 4, does the problem also exist (without using a cylinder shape)? If so, can you post an MRP (the code has changed a lot between v3 and v4).

@jitspoe thanks for the MRP, I have checked your issue, it's a different one (maybe you should open an new issue)

This is a very special case in fact, the space between the walls is exactly the same as the size of the player (if you only add 0.001m of distance (safe margin), the issue disappear).

The first problem I saw was that the body did not detect the floor, but only the walls, so it was not considered on_floor.

Unfortunately, solve this doesn't fix the issue, because I'm pretty sure that the problem is due to how the engine works. When a body collides with something, the engine depenetrates the object by pushing it a bit more than necessary to make sure it isn't stuck on something (because of the approximation I guess).

So in this case, the body is pushed a bit into the wall, and it gets stuck. So not sure we can do something.

Maybe, a hack to handle this special case can be written in move_and_slide, we have to see if it's worth it and if it doesn't cause other problems.

elvisish commented 2 years ago

@elvisish Have you tried with Godot 4, does the problem also exist (without using a cylinder shape)? If so, can you post an MRP (the code has changed a lot between v3 and v4).

Not yet, I've not wanted to try until at least in beta but I can try it and see. The project I posted is a really good test case for these issues and can probably always be used as a cross reference for any bug fixes to either bullet or Godot physics.

fabriceci commented 2 years ago

@elvisish I recommend to try in a minimal way, using the default script template for movement in Godot 4, with that, you only need to add the level that produce the issue. The more minimal the code, the more it isolates the problem.

elvisish commented 2 years ago

@elvisish I recommend to try in a minimal way, using the default script template for movement in Godot 4, with that, you only need to add the level that produce the issue. The more minimal the code, the more it isolates the problem.

I don't use Godot 4 and I'm unlikely to until at least beta as I'm not currently bug hunting GD4, rather I'm interested on GD3 being as solid as possible (could be years until GD4 is stable). The movement I'm using is entirely dependent on move_and_slide() so if there's any bugs it's not likely to be the controller but the KinemeticBody physics as the movement code just inputs a velocity to move_and_slide(). If GD4's default movement works, that would be cool but I'm not sure if it'll make much difference to how GD3 works unless fixes are backported, and unless the GD4 default movement has stair climbing built-in (which I'm pretty it doesn't?) I'd still need to use my movement.

Godot Physics are much more precise for space state work currently, but it's really easy to break move_and_slide() and get totally stuck by just hitting a wall or seam in the wrong way, something that bullet doesn't have any issue with (but is really bad with precision space state work).

jitspoe commented 2 years ago

I'll have to see about making a simpler reproduction level, as I'm using Qodot here with a complex map, but even with the capsule, I'm running into a lot of cases where I get stuck on things and can't move. Sometimes I get launched sky high: https://clips.twitch.tv/FamousClearCrowLeeroyJenkins-girtkzcbvfPqT1Rc

As things currently stand, I think 4.0 is far too broken to release in its current state, since the Godot physics are the only option. This is nearly unusable. Not sure if it's just an issue with move_and_slide() or something more core.

fabriceci commented 2 years ago

@elvisish Yes I understand, move and slide is shared between Godot Physics and Bullet, the cause comes from elsewhere.

I took the time to test your project, I replaced the movement code by a minimal code (to limit factors). After checking, the case you provide, I have these problems only with the cylinder. I think it's the same problem as #57476, as I said previously, currently the contact points returned in case collision with a cylinder has a problem.

Do you experience an issue using a capsule collision shape in your test project?

capsule: capsule

cylinder cylinder

elvisish commented 2 years ago

@elvisish Yes I understand, move and slide is shared between Godot Physics and Bullet, the cause comes from elsewhere.

I took the time to test your project, I replaced the movement code by a minimal code (to limit factors). After checking, the case you provide, I have these problems only with the cylinder. I think it's the same problem as #57476, as I said previously, currently the contact points returned in case collision with a cylinder has a problem.

Do you experience an issue using a capsule collision shape in your test project?

capsule:

capsule

cylinder

cylinder

Try crouching under the back of the stairs, or even just walking around there, definitely some bugs just by moving and colliding behind the staircase. I had issues with capsule and found the least buggy to be box, I just don't rotate the box so it acts as an AABB.

fabriceci commented 2 years ago

@elvisish here is my minimal project based on yours: minimal cylinder.zip I don't see obvious things. If there are additional issues, don't hesitate to open new ones so as not to mix everything up.

fabriceci commented 2 years ago

@jitspoe The previous bug and this one are not related to the issue. We should try to avoid mixing issues in one thread, it will become unmanageable. Please open new issues.

I'll have to see about making a simpler reproduction level, as I'm using Qodot here with a complex map, but even with the capsule, I'm running into a lot of cases where I get stuck on things and can't move. Sometimes I get launched sky high: https://clips.twitch.tv/FamousClearCrowLeeroyJenkins-girtkzcbvfPqT1Rc

I understand the frustration, the thing about physics is that a small bug can have an incredible effect. Please try to reproduce this bug in a minimal project so that we can debug. Major bugs like this will have to be fixed.

jitspoe commented 2 years ago

Noticed something interesting: The cylinder behavior on slopes seems to be a lot better with triangle mesh collision than convex hulls (in Godot 4). It still sticks and hangs up a bit, but at least it doesn't teleport all over the place.

fabriceci commented 2 years ago

@jitspoe did you manage to reproduce the bug that ejects the player? The player collision shape in your video was a cylinder?

jitspoe commented 2 years ago

The clip I posted where I got stuck and launched into the air was with a capsule. Since this bug has been tweaked to specifically deal with cylinders, I will note this:

The problem is not specific to move_and_slide(). I tried implementing my own movement using move_and_collide(), and the cylinder still teleports around and falls through geometry.

fabriceci commented 2 years ago

@jitspoe yes, the cylinders the problem is already identified and understood, this should be fixed. It is not indeed related to move_and_slide, it is the contact points that are wrongly returned by the algorithm for cylinders.

Now that I know that was a capsule, I'm more curious about the bug in the video, it will be great to be able to reproduce it.

jitspoe commented 2 years ago

@jitspoe yes, the cylinders the problem is already identified and understood, this should be fixed. It is not indeed related to move_and_slide, it is the contact points that are wrongly returned by the algorithm for cylinders.

Now that I know that was a capsule, I'm more curious about the bug in the video, it will be great to be able to reproduce it.

I've managed to create a simple reproduction case using a small section of my level and created a new issue here: https://github.com/godotengine/godot/issues/65596