# How to draw triangles with coordinates

Hello. I have set up a 3 dimensional array, which is used to “cover” the whole map with a 3d grid. The array is Boolean, so each coordinate is turned on or off.

I want to make it so whenever an area of coordinates are turned “on”, they create a mesh around them self, that the player collides with and can walk around on. Whenever I turn on another coordinate near it, the mesh adjusts accordingly. Whenever I turn off a coordinate inside the mesh, the mesh creates a hole accordingly. This way, the player can “dig” into a set coordinates, with a realistic mesh that appears to have a newly dug hole.

I am not sure where to start off, because I am not familiar with working with meshes.

SO to sum things up, im asking for help creating code that will draw a mesh around given coordinates. (x,y,z)

(For example, if I turn on one coordinate, i will see a cube. If i turn on 2 next to each other, I will see a rectangle. But if i turn on coordinates in the shape of a sphere, I will see a smooth sphere, not a blocky one).

Even if you don’t know how the mesh generateing around the coordinates works, any help on creating a triangle given 3 coordinates will be helpful.

There are too many unknowns in your project for a clear answer at this point. I suggest you educate yourself in two areas for this project. The first is building meshes. Since you will be building cube-like or lattice structures, create a procedural cube. I suggest using this post:

There is a bug in the code posted with the question (as you can see by the image). There are working examples of procedural cubes, but understanding and fixing the bug will help you understand triangle winding and normals, which is very important to your project.

Once you have the cube up and working, take a look at uv coordinates. This is likely how you will define and change the texture of all the faces of the cubes.

Ok, I am going to start from scratch. Can anyone help lead me to a magical function that basically does this:

DrawATriangle(x1,y1,z1,x2,y2,z2,x3,y3,z3)

NO unnecessary objects.
NO meshes to be “attached” to the objects.

I know this probably doesn’t exists, but if it does, please let me know.

I noticed that there is a game called minecraft that people are cloning. I can tell that there are thousands of cubes being drawn. Im sure there isn’t one object per cube, and it is probably controlled by one 3 dimensional array like my game is. Can anyone tell me how they draw the cubes in there game? Hopefully, I can take this knowledge and draw a customizable triangles instead of a cube

I know this is an old thread but for anyone trying to do a similar thing who isn’t up to building meshes in script you can just create a cube prefab and instantiate the whole cube in whenever a block is cleared.

Of course it will be less efficient since you’ll have the whole cube even when some of the faces are hidden, but it’s a simpler method and will allow you to move onto mesh building later once you’ve made some progress.

Here you can learn step by step how to draw a triangle just by code (Turn on English subtitles)