Vehicle gets stuck at collisonShape from GridMap

Godot Version

4.2.1

Question

The floor is made of tiles in a GridMap, each with a size of 1 x 0.1 x 1 m. For some reason the vehicle seems to get stuck sometimes for no visible reason, see video below:

When you see the vehicle standing still in the clip, I am actually pressing the keys for forward or backward but nothing happens.

Any ideas?

Ghost collision on edge seams is a common physics engine problem. You can read about it under that term.

Basically your gravity sinks your physics body to deep into the ground and because your collisions shapes are not a connected surface the collision testing collides with an internal face edge.

You do not see this sink-in-ground because the rendering does not update in that time and when a physics engine detects that bodies overlap it corrects them back to valid positions. In this case what the physics engine deems valid is not what is intended but for the physics engine that internal block edge is valid in the calculation.

Nodes like TileMap or GridMap amplify how visible this ghost collision issue becomes because they add so many edge seams between their cells on what should be otherwise a single, connected and flat physics face.

Note that not every project has this issue. It depends on used shapes, tickrate, speed, angle and luck. The best way to solve this is not to use cell based collision and instead merge your cells manually with scripts to a combined collider surface.

1 Like

thanks for sharing

@smix8 thanks for the great explanation! Too bad this is not listed as potential caveat in the official documentation for GridMap.

Regarding

The best way to solve this is not to use cell based collision and instead merge your cells manually with scripts to a combined collider surface

Do you have any example for me how that would look like or pointers where to start reading up? :slight_smile:

I dont have an example but it is basically how you would crawl through voxel cells. You start with one “ground” cell and “flood” through the neighbor cells checking if they are also valid ground cells at the same height with nothing over them. With all those cells collected you calculate their outline edges and create one or more convex collision polygons for a StaticBody3D out of them.

Also the newest Jolt Physics version apparently did a lot of work on ghost collisions with flat surface collision seams. I guess it should be suggested to all GridMap users plagued by this to give it a try. I am not sure if it is already in the Godot version of Jolt because it was only announced like 3-4 days ago by the Jolt developer.