Hi all! It's nice to be here 🙂
I am working on some terrain generation in Godot 4.0.3. I have a vertex shader that deforms a mesh, and I am generating a HeightMapShape3D for a CollisionShape3D. I am loosely following this tutorial by devmar.
I am having trouble getting the HeightMapShape3D to match the shape of the mesh. The HeightMapShape3D is much flatter than the Mesh and does not have the same shape.
I have experimented with the following:
- Normalization of the noise function I am using
- Using
get_image
on the noise texture and usingget_pixel
instead of sampling withget_noise_2d
- Importing the noise as an image instead of using NoiseTexture2D
- rotating the mesh in each of the four possible orientations (0, 90, 180, and 270-degree rotations)
- Iterating over different ranges of x and y values (-range to zero, -range/2 to range/2, 0 to range, and most combinations of those, as well as most of those combinations with +1s thrown around)
- dividing by xz_scale instead of multiplying by it, many other misc scaling tweaks
The result looks something like this, where the mesh undulates above and below the collider, instead of the collider having roughly the same shape as the mesh.
I've also attached a minimum repro project if you'd like to take a look at my setup.
Based on how long I've been trial-and-erroring this, I think I'm just misunderstanding something fundamental. Any ideas on where I'm going wrong? I am also open to other strategies for programmatically creating collision shapes for terrain if this isn't a good strategy.
Thank you!