你好,我是法國人,所以請原諒我的英語不好,我用預制游戲物件的種子創造了一代土地,但它們從一列到另一列產生,所以我想創建這個,但像蝸牛一樣從中心到外面,但在正方形
我部分成功了,第一張圖片顯示了 columne 中的生成,但也顯示了蝸牛生成的預期最終結果,第二張顯示了我在蝸牛中設法做的事情,但我的土地是方形的,看起來很糟糕
- 第一的:

- 第二:

- 它的作業原理如下:

- 我希望它像這樣作業:

uj5u.com熱心網友回復:
假設您從原點 O 開始,其他 4 個方向是 E、S、W、N
N
W O E
S
那么你要移動的步驟順序是
E S
W W N N
E E E S S S
W W W W N N N N
...
您可能會注意到,每轉兩次,就需要將向該方向移動的次數增加一次。
一些偽代碼:
var dirs = new Vector3[] { E, S, W, N } // 4 directions
Vector3 pos = O; // origin
do
{
var dir = 0
var moveTimes = 1
for (i = 0; i != 2; i)
{
for (j = 0; j != moveTimes; j)
{
pos = dirs[dir]; // step forward
}
dir = (dir 1) % 4; // turn
}
moveTimes ;
}
while(/* condition to stop */);
uj5u.com熱心網友回復:
好的,我找到了解決方案,但我認為這不是最好的解決方案
for(int i = 0; i != Size; i )
{
if(i == Size - 1)
{
for (int y = 0; y != moveTimes; y )
{
pos = dirs[dir];
GameObject inst = Instantiate(TileMap, pos, Quaternion.identity);
inst.GetComponent<MapGeneratorChunk>().ID = SetID;
inst.GetComponent<MapGeneratorChunk>().Seed = Seed;
print("hello");
}
dir = (dir 1) % 4;
for (int y = 0; y != moveTimes; y )
{
pos = dirs[dir];
GameObject inst = Instantiate(TileMap, pos, Quaternion.identity);
inst.GetComponent<MapGeneratorChunk>().ID = SetID;
inst.GetComponent<MapGeneratorChunk>().Seed = Seed;
print("hello");
}
dir = (dir 1) % 4;
for (int y = 0; y != moveTimes; y )
{
pos = dirs[dir];
GameObject inst = Instantiate(TileMap, pos, Quaternion.identity);
inst.GetComponent<MapGeneratorChunk>().ID = SetID;
inst.GetComponent<MapGeneratorChunk>().Seed = Seed;
print("hello");
}
dir = (dir 1) % 4;
}
else
{
for (int x = 0; x != 2; x )
{
for (int y = 0; y != moveTimes; y )
{
pos = dirs[dir];
GameObject inst = Instantiate(TileMap, pos, Quaternion.identity);
inst.GetComponent<MapGeneratorChunk>().ID = SetID;
inst.GetComponent<MapGeneratorChunk>().Seed = Seed;
}
dir = (dir 1) % 4;
}
moveTimes ;
}
}
結果
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/399155.html
