Hi, guys. I am messing around on Unity and decided to have a chunk generator that has bias to a specific object. For example, I would have bias to dirt and would occasionally have stone. This works fine currently. However, when I try to fill the areas between the biased object, there are many gaps. I have used Physics.CheckSphere();
to check whether or not an object already exists there. If somebody could suggest a fix to these gaps, and/or a more effective way of filling these gaps, I would really appreciate it. Also, keep in mind I am new to Unity and haven’t spent too much time with C#. If any more information is needed, please ask.
Code:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class LoadChunk : MonoBehaviour
{
public void Load(int chunkSize, Transform bias, Transform other)
{
for (int xPos = -chunkSize; xPos < chunkSize; xPos++)
{
for (int zPos = -chunkSize; zPos < chunkSize; zPos++)
{
for (int i = 0; i <= 15; i++)
{
Instantiate(bias, new Vector3(xPos, Random.Range(0, 64), zPos), bias.rotation);
}
}
}
for (int xPos = -chunkSize; xPos < chunkSize; xPos++)
{
for (int zPos = -chunkSize; zPos < chunkSize; zPos++)
{
for (int yPos = 0; yPos < 64; yPos++)
{
if(!Physics.CheckSphere(new Vector3(xPos, yPos, zPos), 0.5f))
{
Instantiate(other, new Vector3(xPos, yPos, zPos), other.rotation);
}
}
}
}
}
public void LoadOneType(int chunkSize, Transform block)
{
for (int xPos = -chunkSize; xPos < chunkSize; xPos++)
{
for (int zPos = -chunkSize; zPos < chunkSize; zPos++)
{
for(int yPos = 0; yPos < 64; yPos++)
{
Instantiate(block, new Vector3(xPos, yPos, zPos), block.rotation);
}
}
}
}
}