RandyGaul / qu3e

Lightweight and Simple 3D Open Source Physics Engine in C++
zlib License
920 stars 110 forks source link

Sliding boxes "catch" on edges in floor #58

Open njbradley opened 2 years ago

njbradley commented 2 years ago

Hello! First of all, thank you for this library, I've been using it in my own voxel game, and it has been worked great! However, I've been stuck on this problem and I'm not really sure how to approach it.

Basically, the problem is that because this is a voxel game, the floor is made up of a bunch of different boxes. When objects slide on top of the floor, sometimes they will catch on a seam between two boxes and stop suddenly. I think this is happening because the object sliding on top is slightly protruding into the floor, and this part collides with the sides of the boxes in the floor.

Do you have any ideas to solve this? I tried changing the collision detection to ignore collisions on the very edge of boxes, but it's been hard to do this without ignoring actual collisions. Any help is appreciated!

Thanks!

RobQuistNL commented 2 years ago

how about you make the boxes slightly bigger? so they overlap?

njbradley commented 2 years ago

Hmm, I tried that and it didn't seem to make a difference. I think because the sliding object is still protruding into the floor, it collides with the sides of the boxes. I'm thinking I might just write some code to disable the "internal" faces. Thanks for the suggestion!

RandyGaul commented 2 years ago

Yeah this is a common problem. There are many ways to tackle the solution, but the one I'd suggest is to add sphere collisions and use a sphere when sliding over the ground. This way the rounded edges can not get caught on the seams between boxes. It wouldn't be very difficult to add, and I can help you if you'd like to make a pull request to add spheres.

njbradley commented 2 years ago

I see, that makes sense! I was able to get it working by ignoring collisions on the internal faces, but I might need to use spheres later on. I'd be happy to implement spheres anyway, it seems like that would be a useful addition, and not too hard.

RandyGaul commented 2 years ago

Ignoring internal edges isn't going to be a very practical solution here. Of course you can try, but I think sphere will be far easier to get working robustly.

njbradley commented 2 years ago

The only reason I'm not going with the spheres is that I'd like to keep all the objects cubes. I feel like a cube collider with rounded edges would be perfect, but that sounds pretty difficult to make. I agree, disabling internal faces is not the best solution, but I can't think of a better one that keeps the sliding objects as cubes.

RandyGaul commented 2 years ago

One thing you can do is use a compound collider of both a sphere and a cube, then toggle each behavior depending on the scenario. You only need sphere when things are sliding around.