Hello, this is my first question on the forums. I was looking all over the internet,but I found no answer. I am making a game, which should generate land as you walk. Heres my code:
var land : GameObject;
var xpos : float;
var zpos : float;
var xuse : float;
var zuse : float;
function Update () {
xpos = transform.position.x / 50;
zpos = transform.position.z / 50;
xuse = Mathf.Round(xpos) * 50;
zuse = Mathf.Round(zpos) * 50;
var hit : RaycastHit;
if (!Physics.Raycast (Vector3(xuse,1,zuse), Vector3(xuse,-1,zuse), hit, 5.0)) {
Instantiate(land,Vector3(xuse,0,zuse),Quaternion.identity);
print("Land instantiated");
}
else {
if (hit.transform.tag == "Land") {
print("Land found");
}
}
}
This might not be most efficent way to do it, but anyways. So when I walk it generates ground below me on a grid of 50. The problem is when it raycasts and finds nothing below it generates ground, but it doesnt detect it with raycast so it keeps infinitley generating it. I found on another post that checking for tags, but this isn’t working since its kind of opposite. I really have no idea what to do. Waiting for any answers.