Zylann/godot_heightmap_plugin

Collider and Terrain not always exactly the same height?

Closed this issue · 4 comments

Sometimes this happens to me, that the collider and the terrain seem to have not always exactly the same height:

Bildschirmfoto von 2024-05-01 23-15-16

Again this is still Godot 3, but do you know a solution for this?

Once again I can't really tell you what this exactly is, because the Godot 3 version is old, and Godot 3 is old too, and I stopped working on that version years ago. I could maybe check this if you see it happen in the current version in Godot 4.
I vaguely remember that there has been a fix that was done at some point where collision was a bit off. I don't remember what it was though, or when. But there could be many other causes I don't even have time to list.
Looking at your screenshot, I fail to distinguish what kind of mismatch you are having. Just the camera clipping with ground?
Another 2 things to keep in mind, is that terrain visuals have LOD, but the collider doesn't. So it won't perfectly match the further away you look. Also, visuals use a diamond-shaped triangles topology, while I believe Bullet/GodotPhysics seem to be using zig-zag triangles (so half of the quads have flipped triangles), so you can't really expect an absolutely perfect match. This is usually not much of a problem though, and you might only be able to see that if you use a very scaled up terrain with large triangles maybe.

I made a short video, maybe it helps to see the problem: https://youtu.be/j8OOqpq9-1Q

I do know that I can't expect support for an old version, so I'm really thankful for any hint you give me!

If I understand the video correctly, your character is extremely small and walks on a terrain with very big triangles?
If so, then I suspect the discrepancy is simply the choice of geometry for rendering it:

visuals use a diamond-shaped triangles topology, while I believe Bullet/GodotPhysics seem to be using zig-zag triangles (so half of the quads have flipped triangles)

In your video the character is so small and terrain triangles are so big that it probably becomes noticeable. It's just designed that way, and wasn't intented for extreme situations like this one.

If you still want such big triangles and such small player in your game, here is the place where visual triangles are flipped (in the master version, but I think it's roughly the same in yours):

var flip = ((x + reg_origin_x) + (y + reg_origin_y) % 2) % 2 != 0

I got it fixed by setting every triangle to flipped. Thx for the hint!