- Home /
Sample 3d float array
How would I sample a 3d float array based on world position?
What do you mean by "sample"? Do you want to know how to declare and fill 3-dimensional arrays?
No I want a way to do this\/
PickaxePos = Pickaxe.transform.position; voxels[(int)PickaxePos.x, (int)PickaxePos.y, (int)PickaxePos.z] +=1;
but more accurate.
I'm sorry, I still don't get it :) It would help if you could format your code as code (looks like there's something missing), and also describe in your own clear words what you are trying to achieve. Is "voxels" a 3-dimensional float array? Why does it need to be more accurate?
sorry cant format it wont work. I said that it was a 3d array in the question. I want to be able to sample the float array so I can dig its a voxel terrain Im not sure how its supposed to work but it has been done lots in voxel terrains.
Ah, now we are on the same page. I still don't know why you keep using the word "sample" but anyway, I would like to ask why you use a float array ins$$anonymous$$d of int? Voxel games typically use ints because they can be byte-encoded easily and each value can only represent one dimension.
Oh well, here is a good tutorial that shows you how to find the voxel position based on a RaycastHit, which you can just replace with your own Vector3 (PickaxePos, in your case).