[SOLVED] Multiple Procedural Mesh collisions not working?

Hello!
My progress in my voxel game is going great! I just recently figured out how to make a 10x10 voxel world… and it runs at 60 frames despite rendering thousands upon thousands of polygons!

Look at my progress so far:
Before:


(Garbage ugliness!)

After:


(Beautiful voxels!)

But my issue now is the collision system. Currently, it works perfectly for the main chunk at [0, 0, 0], but all the other chunks have very inconsistent collision meshes. If I walk around, I am fine, up until I go to another chunk, where I just fall through the floor. My code is no different, and yet it acts different.

Any help is appreciated!
Project:
https://playcanvas.com/editor/scene/1439135
(I cleaned up my code, so now the problem child resides in chunk.js instead of game.js)

Hi @Kurios,

That looks awesome, very well done!

When I have trouble with mesh colliders, I try to use the Ammo debug view to be able to actually see/visualize the colliders.

Check this extension by @LeXXik, it’s of great help on this:

Thank you @Leonidas!
Here are the results of my find:



I guess the problem is more complicated than I thought… how can this be? There seems to be a condition that I am not aware of. If you do not know, feel free to pull in anybody else who may know about abstract things like procedural generation.

Thank you.

Not sure what may be wrong, but what may help for start is to reduce the size of your map. Then visually debugging the meshes may be easier.

@LeXXik do you have any other ideas on how to approach this?

Well, it is hard to say without some debugging. The current code is hard to debug, and I mean, I can’t open it, glance through and say - hey the problem is there. You’d need to spend time studying the math that is used in the code.

What I would recommend is make your voxel world 2x2x2, making it basically an 8 voxels only. Once there, make sure you can remove a voxel from each corner of the world. Once done, double the size of your world and make sure you can still remove the voxels from your corners. Once done, make sure you can remove/add any arbitrary voxel from/to world. Once done, you can expand your world to larger scales.

Ammo Debug Drawer that Leonidas suggested is helpful for debugging this. I have in my todo list to update it to allow people to adjust the lines draw distance, so it doesn’t clutter the screen with far away meshes.

1 Like

I took your advise and started smaller. Luckily, I found the issue. It is not that the collisions are not there, but that they are separated from the mesh somehow. I think that the x16 scalar to space out the chunks are somehow affecting the collisions separately from the meshes. But, setting the graph nodes Local Position to zeros do nothing.

Hopefully this helps.

That looks close! I tried launching your project via the url you shared in your initial post and it seems to be working?

I can’t move around but I can see the collider matching the voxels:

Yeah, you may have to make your own player controller. Since I am using my phone for all of this, I made a primitive touch controller to look around and navigate. You may be seeing the first chunk, which DOES have the collisions in the right place. It is really the others branching off from the corner that are being problematic.

If the collisions all work on your end, I may have to transfer my code to a new project…

Thank you @Leonidas and @LeXXik! I took your advice and solved the problem, albeit relatively inefficient.

I experimented small, and found the issue. For whatever reason, the GraphNode transformations of the visual mesh and the collision mesh were acting different. But, when I tried to give them separate variables, it still would not work. Either the collision mesh was fixing itself and the visual mesh acting up, or vice versa.

So, my solution was to create a sub-entity parented under the chunk entity, assigning its collision model from the chunk entity, and transforming the node via the sub-entity.

Even though it is essentially doing the same thing I tried from the beginning, the engine is treating it differently. But it works!

Beautiful voxels:

3 Likes

Very nice, it’s good that you are unblocked now, looking forward to this project!