• 3D
  • How to properly handle collisions with a GridMap ?

Hello,

I'm learning Godot and I am trying to work with a GridMap. The player is KinematicBody (a ball) that can move forward / fall. The world is composed of two elements: one GridMap composed of 1x1x1 blocks (blue) and one StaticBody (red) associated to a collision shape

When the ball is rolling on the StaticBody everything looks fine and smooth. When the ball is rolling on the GridMap blocks there are "bumps" between each blocks

In my MeshLibrary the MeshInstance has a StaticBody as a child, which has a CollisionShape as a child which is a block of the same size of the visible geometry. I have tried making it a little bigger/smaller but it does not help.

Video of the bumps

How do I avoid the bumps between each block on the GridMap? (full project enclosed) You can move the ball over the red StaticBody to test what works.

I have not looked at the video or project, but when I was working on the FPS tutorial for the Godot documentation I think I had this issue. From what I remember, in that case the issue was that I had scaled StaticBody or CollisonBody nodes, which may be the issue in this case. Making all of the StaticBody and CollisionBody nodes have a scale of 1 fixed the issue for the FPS project.

I'll try to take a look at the project later and see if I can figure out what is going on.

None of the bodies have a different scale than 1 so I don't think it could be the problem!

Perhaps it's a precision issue, if your gridmap blocks were large enough to overlap a bit with each other then perhaps there will be no virtual caps to bump against?

I downloaded the project and found good news and bad news.

The good news is that the issue is not the Gridmap or the collision shapes in the Gridmap. Enabling visible collision shapes in the Godot editor (Debug -> Visible Collision Shapes) shows that the size of the collision shapes is correct.

The bad news is, the issue seems to be because of the seams between collision shapes. I tested this by placing one of the red StaticBody rectangles after the first one, and on the seam it has the same issue. I also tried increasing the collision shape margin, as @Megalomaniak suggested, but it didn't solve the issue.

I'm not sure where the issue is, to be honest. I'm wondering if the issue is in code, but I'm not sure where it would be and I currently do not have the time to take a detailed look through the code and how it works. I did a few quick tests but I couldn't find a solution or what may be causing the issue. It could also be a physics bug, but again, I'm not sure.

Another related issue is issue #35780. Seems it is something to do with a change after Godot 3.1, what is stated in the linked issue is correct.

If you have a github account you might want to add a comment there letting them know that it has fixed an issue for you, cause the way I read it, there's a chance it might not as it currently stands, make it into a official/stable release.

To be fair though, the reason they are hesitant to merge the pull request is because they suspect it only fixes some of the symptoms and not the true underlying cause. A proper fix for the real cause if it can be found is ideally the better solution, obviously.

Too many band-aids makes the code base harder to maintain after all.