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…
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:
(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:
(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:
(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.