Digging Terrain

I want to be able to delete terrain voxels which I have mostly accomplished, It works fine when the terrain voxe I am trying to delete has 100% occupancy and the terrain perfectly fits the 4 x 4 x 4 grid voxel cell. There is a game called Attrition which does what I’m trying to do perfectly. I’m basically making a delete tool that functions the same as their delete tool in their game because I am making a similar thing based on my favourite childhood game RorFare. (which is also a build and battle game like attrition) E.G.1: https://gyazo.com/e66afec9d7f38c66934d0fa7b9b7a7ac, E.G.2: http://https//gyazo.com/78f41e5a1af0fc48570b86131ef66865?token=62d2fac6912deafcdf3e161602430385

This is what my tool looks like compared to that so far: E.G.1: https://gyazo.com/299d70ec210be16d2c7f3e8dc1131dcb, E.G.2: https://gyazo.com/10700974b7e92efe869052b85e9cd9c6

However Geometry can be outside of the occupied voxel if the material is something like grass which doesn’t always fit all inside the voxel as a perfect cube like brick or wood does. and I believe I only want to delete voxels with 100% occupancy so that it automatically gets rid of any geometry that may be outside of that occupied voxel. Or I could completely ignore geometry that seeps outside of the voxel somehow so that it works perfectly as it does with normal voxels that don’t have weird geomtry going on that expand outside of it’s own voxel.

I noticed these functions exist: WorldToCellPreferSolid which aproximates that and prefers solid cells. The only problem is I don’t know how to integrate that function so that my red block CFrames in a way to only prefer solid voxels and I’m not sure if it is possible to integrate it as the red delete block moves with the players mouse and increments along the terrain grid.

Another solution I can think of is to somehow convert this code,

local solidCell = game.Workspace.Terrain:WorldToCellPreferSolid(mouse.Hit.p)

so that I can use the position of the solid voxel and then CFrame my red deletion block to that voxel. The thing is I have tried this and the position of the terrain voxel doesn’t seem to corrilate to the world positon and there for my deletion block CFrames somewhere really far away completely in the wrong position. I also don’t know If I am simply doing this wrong or if it’s even possible.

Thanks for reading, sorry if I didn’t explain in enough detail I don’t want to make this post too long and boring and I hate asking for help.

1 Like

I solved the problem, this topic is solved, I don’t want to be that guy that just says “solved”, so basically I was already moving the block along the terrain grid using math and I used this code

local solidCell = game.Workspace.Terrain:WorldToCellPreferSolid(mouse.Hit.p)

If you read the whole post you know I already tried this however before it was not alligning the object to the terrain grid using this method but it is now, I got the x, y, z positions from the code above and * them by 4 in order for the deletion part to move along the terrain grid. I then used WorldToCellPreferEmpty when I wanted to build terrain instead of delete terrain. My terrain tool actually works exactly like the one from attrition. Hoped this helps a bit, still cant believe I pulled it off lol.

If you would, please post your solution to avoid dead-end searches when another user has your problem. The post marked a solution should, ideally, have the solution and not say “Solution.”

I’m personally interested in how you solved this.


If need anything else you can pm me