Flat heightmap collision

Hey, I’m new to jmonkeyengine and I’ve been reading through the tutorials and forums like crazy but I have two issues with terrains that I can’t resolve.

  1. Collision with flat heightmap isn’t working. I’m using a terraingrid, but this also happens when i just use one terrainquad based on a completely flat heightmap, all other terrain collision is working fine for me. If i change the heightmap so that one pixel is different suddenly the terrain becomes solid, it’s bizarre to me. The flat terrainquads that are generated when no heightmap is found are solid. I tried changing the stepheight, but that doesn’t fix anything. I could post code but I’m not sure what exactly is the most relevant and I’m just using really basic collision code from the demos. Any ideas? I just want to solve this to make sure I’m doing the collision correctly.

  2. Terraingrid quad size. When using size 257 heightmaps and not changing the localscaling, the terraingrids place a new terrain right in front of you. I’ve heard that you need to make sure the size of your terrainquads is like 2x the size of your view distance? is that correct? if so, with like a 257 size heightmap it seems like i need to scale it like over 10x or something crazy like that, if using like a 5k farplane for your view frustum (the 1k far plane view frustum seems unnaturally close to me). Is scaling it that much what I should be doing? That seems to be a really large area for such few vertices to me. I don’t really understand why terraingrids are only 4 terraingrids, I feel like it should be 3x3, so that you are always in the center. By the time the terraingrid determines that it needs to recenter you, you’re extremely close to the edge. Any thoughts?

Yep, exactly. I’ve made this same argument for 8 years now. All of the arguments for 2x2 fall down if examined closely. (In fact, there are lots of other parts that could have been done better. Stitching is 100% unnecessary and wasteful, etc.)

Unfortunately, the folks doing that work had already done that work and weren’t real keen on rewriting it all from scratch. They left shortly after and no one has really picked up the issue enough to redo anything.

I suspect that anyone really serious about a game long term ends up using the built in terrain system as a starting point and ultimately rewriting it to their needs.

You can pick away at this, or use it.

https://jmonkeystore.com/994b4082-8191-4622-9c44-ffc49c31a67d

Just wanted to let everyone know, I found out why terrainquads/terraingrids from completely flat heightmaps didnt have working collision for me. I was using 257x257 size heightmaps, because I thought terraingrid requires the actual heightmaps to also be a power of 2 + 1? I’m still not completely sure but anyway… With terraingrids, collision for flat heightmaps of that size does not work. But i was also testing the collision of one of those flat 257x257 heightmaps with just a terrainquad and it wasn’t working, but when i switched to a flat 256x256 heightmap it works

1 Like