Building system, any assets or guides?

Well, yesterday I decided to make a build system, similar to Unturned or Rust…

So, I started to search and I didn’t find anything, no assets, no guides, I found only this video: - YouTube (It’s a bit surprising, but…)

This is something similar to the thing I want to make, but there isn’t any asset (for explore it, and give me ideas about how can I make that)

Maybe I’m searching it in the wrong way, so, can somebody give me some guides about that? I would be so grateful. =]

PD: I know that a basic system is instantiate a gameobject but I want to know how can I make the grid and how can I detect where can I instantiate the object and where not (it’s a AI?)


Now, I’m having trouble to make a smart system for detect where can be the next block…

smart block system

Well, the black square is a 3D cube in scene, and the squares inside it are the positions that the script detects and sets where the block will be… (And the purple lines are where the following block will be put)

The problem is that I’m confused because there are 9 positions to set:

public enum FloorAprox {Top, Left, Right, Bottom, None}
 
Vector3 nearPos = nearestFloor.transform.position-nearestFloor.transform.localScale/2;
Vector3 fNearPos = (nearestFloor.transform.position+nearestFloor.transform.localScale)-nearestFloor.transform.localScale/2;
float[] xMiddlePos = new float[2] {Mathf.Lerp(nearPos.x, fNearPos.x, 0.25f), Mathf.Lerp(nearPos.x, fNearPos.x, 0.75f)};
float[] zMiddlePos = new float[2] {Mathf.Lerp(nearPos.z, fNearPos.z, 0.25f), Mathf.Lerp(nearPos.z, fNearPos.z, 0.75f)};
if(hit.point.x >= nearPos.x && hit.point.x < xMiddlePos[0] && hit.point.z >= nearPos.z && hit.point.z < zMiddlePos[0]) {
    fscript.xAprox = FloorAprox.Left;
    fscript.zAprox = FloorAprox.Top;
} else if(hit.point.x >= xMiddlePos[1] && hit.point.x < fNearPos.x && hit.point.z >= nearPos.z && hit.point.z < zMiddlePos[0]) {
    fscript.xAprox = FloorAprox.Right;
    fscript.zAprox = FloorAprox.Top;
} else if(hit.point.x >= nearPos.x && hit.point.x < xMiddlePos[0] && hit.point.z >= zMiddlePos[1] && hit.point.z < fNearPos.z) {
    fscript.xAprox = FloorAprox.Left;
    fscript.zAprox = FloorAprox.Bottom;
} else if(hit.point.x >= xMiddlePos[1] && hit.point.x < fNearPos.x && hit.point.z >= zMiddlePos[1] && hit.point.z < fNearPos.z) {
    fscript.xAprox = FloorAprox.Right;
    fscript.zAprox = FloorAprox.Bottom;
} else if(hit.point.x >= xMiddlePos[0] && hit.point.x < xMiddlePos[1] && hit.point.z >= nearPos.z && hit.point.z < zMiddlePos[0]) {
    fscript.xAprox = FloorAprox.None;
    fscript.zAprox = FloorAprox.Top;
} else if(hit.point.x >= nearPos.x && hit.point.x < xMiddlePos[0] && hit.point.z >= zMiddlePos[0] && hit.point.z < zMiddlePos[1]) {
    fscript.xAprox = FloorAprox.Left;
    fscript.zAprox = FloorAprox.None;
} else if(hit.point.x >= xMiddlePos[0] && hit.point.x < xMiddlePos[1] && hit.point.z >= zMiddlePos[1] && hit.point.z < fNearPos.z) {
    fscript.xAprox = FloorAprox.None;
    fscript.zAprox = FloorAprox.Bottom;
} else if(hit.point.x >= xMiddlePos[1] && hit.point.x < fNearPos.x && hit.point.z >= zMiddlePos[0] && hit.point.z < zMiddlePos[1]) {
    fscript.xAprox = FloorAprox.Right;
    fscript.zAprox = FloorAprox.None;
} else {
    fscript.xAprox = FloorAprox.None;
    fscript.zAprox = FloorAprox.None;
}

And there is a simple explanation about it:

floor explanation

(1): Is the center, and well, I had to adjust the positions substracting the scale divided by two, this is (2): nearPos and (3): fNearPos…

So, for get the position in the cube we use Mathf.Lerp:

explanation 2

(1): X = 0.25f; Y (Z) = 0

(2): X = 0.25f; Y = 0.25f

(3): X = 0.75f; Y = 0

And so on…

A screenshot:

screenshot

(There the smart system wasn’t implemented yet…)

For some reason it doesn’t work correctly, I don’t know where is the mistake, so can somebody help me with this? :-/

Thanks in advance.

Bye.

It’s not something recommended for beginners, but it’s certainly no programming mastercraft either. That being said, I take a “look” (it’s over 50 pages long!) at the “After playing Minecraft” thread:

http://forum.unity3d.com/threads/after-playing-minecraft.63149/

to get loads of information on procedural generation.

You have to decide how your building will actually be made up; If the total number of objects of each building is fairly low (in the low hundreds), and you don’t have too many buildings in the scene, then you could go with simple Prefabs for each building part, with each one having a small script that tells you where any connecting parts will go. After that, is just a matter of Raycasting against each building element, checking that element’s connecting point, and instantiating the chosen new element at this position.

If you want really expansive buildings and landscapes, you wil probably want to go fully procedural and create your own meshes from code, as shown in the thread and various tutorials. Just remember that with script-generated meshes, you are not limited to cubed or planes; Theoretically, you could create any shape you want (as long as the total mesh has below 65k vertices).

P.S.: The grid could be just a three-dimensional array “int[,]” with the xyz coordinates as the array dimensions, and the resulting int as, for example, the type of element for this position, like 0 = clear, 1 = wall, and so on… Or you could have the same array for a custom class that stores thigns like materials, damage and so on.