This is going to sound ridiculous but uh…how do I create a radial brush whose size I can control on demand? I haven’t ever had to do anything like that before, and when I try to Google the solution all I find is solutions involving System.Drawing and ellipses, nothing actually stating how. The only way I could think of is to create a manual brush like this:
int[,] wormBrush = new int[5, 5]
{
0, 0, 1, 0, 0
0, 1, 1, 1, 0
1, 1, 1, 1, 1
0, 1, 1, 1, 0
0, 0, 1, 0, 0
};
Other than that, I found a solution last night that creates the worms, they are looping around on themselves and traversing the map happily now. But altering their size would be an awesome addition. Here is the worm code I created, tell me what you think:
private void CreateWorm(ref BlockData[,] blocks, TerrainType terrain)
{
Vector2 wormDirection = new Vector2(
Mathf.Floor(UnityEngine.Random.Range(-1f, 1f)),
Mathf.Floor(UnityEngine.Random.Range(-1f, 1f)));
int wormLifetimeMax = UnityEngine.Random.Range(50, 101);
int currentWormSteps = 0;
Vector2 currentWormPosition = new Vector2(
Mathf.Floor(UnityEngine.Random.Range(0f, dimensions.x)),
Mathf.Floor(UnityEngine.Random.Range(0f, dimensions.y)));
while (currentWormSteps < wormLifetimeMax)
{
// The amount of steps the worm will take this turn
int moveAmount = UnityEngine.Random.Range(5, 11);
// Until we have taken the appropriate number of steps, loop
for (int currentStep = 0; currentStep < moveAmount; currentStep++)
{
// Validate worm position and punch blocks
if (!ValidPosition(currentWormPosition, 1, ref blocks, terrain))
return;
// Move the worm
currentWormPosition += wormDirection;
// Increase worm steps
currentWormSteps++;
}
// Will the worm move a negative amount?
bool isNegativeX = false;
bool isNegativeY = false;
// Decide if the worm will move a negative amount
if (UnityEngine.Random.Range(0, 2) == 1)
isNegativeX = true;
if (UnityEngine.Random.Range(0, 2) == 1)
isNegativeY = true;
// Create a new direction based on random perlin
if (isNegativeX isNegativeY)
{
// Get a new random perlin direction
wormDirection = new Vector2(
-Mathf.RoundToInt(PerlinNoise.GetNoise(UnityEngine.Random.value, UnityEngine.Random.value, 0)),
-Mathf.RoundToInt(PerlinNoise.GetNoise(UnityEngine.Random.value, UnityEngine.Random.value, 0)));
}
else if (isNegativeX)
{
// Get a new random perlin direction
wormDirection = new Vector2(
-Mathf.RoundToInt(PerlinNoise.GetNoise(UnityEngine.Random.value, UnityEngine.Random.value, 0)),
Mathf.RoundToInt(PerlinNoise.GetNoise(UnityEngine.Random.value, UnityEngine.Random.value, 0)));
}
else if (isNegativeY)
{
// Get a new random perlin direction
wormDirection = new Vector2(
Mathf.RoundToInt(PerlinNoise.GetNoise(UnityEngine.Random.value, UnityEngine.Random.value, 0)),
-Mathf.RoundToInt(PerlinNoise.GetNoise(UnityEngine.Random.value, UnityEngine.Random.value, 0)));
}
else
{
// Get a new random perlin direction
wormDirection = new Vector2(
Mathf.RoundToInt(PerlinNoise.GetNoise(UnityEngine.Random.value, UnityEngine.Random.value, 0)),
Mathf.RoundToInt(PerlinNoise.GetNoise(UnityEngine.Random.value, UnityEngine.Random.value, 0)));
}
}
}
The terrain is looking better already, especially when you zoom in and traverse the tunnels as a player it feels much better now. We still have adjustments to make though, the worms are moving a little too diagonal for my liking, so once I figure out this radial brush thing I will try your theory (although it feels a bit over my head lol). Check it out, using the worms to create air, dirt, and stone, in addition to perlin generated stone and dirt patches.