Skip to content

Instantly share code, notes, and snippets.

@todorok1
Created January 6, 2021 16:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todorok1/71a6ec8709c447b3a5012ab706dd24e0 to your computer and use it in GitHub Desktop.
Save todorok1/71a6ec8709c447b3a5012ab706dd24e0 to your computer and use it in GitHub Desktop.
パーリンノイズを重ね合わせてより自然な地形を作ることを目指したサンプル
/// <Summary>
/// 生成(加算変化)ボタンが押された時のメソッドです。
/// </Summary>
public void OnPressedAddPerlinButton()
{
isAddMode = true;
GenerateMultiPerlinFieldParts();
}
/// <Summary>
/// 生成(乗算変化)ボタンが押された時のメソッドです。
/// </Summary>
public void OnPressedMultiplePerlinButton()
{
isAddMode = false;
GenerateMultiPerlinFieldParts();
}
/// <Summary>
/// フィールドを生成するメソッドです。
/// </Summary>
void GenerateMultiPerlinFieldParts()
{
for (float z = 0f; z < fieldSizeZ; z++)
{
for (float x = 0f; x < fieldSizeX; x++)
{
// パーリンノイズの座標を指定して値を取得します。
float xValue = (xOrigin + x) * scale;
float yValue = (yOrigin + z) * scale;
float perlinValue = isAddMode ? GetAddedPerlinNoise(xValue, yValue) : GetMultiplePerlinNoise(xValue, yValue);
float height = fieldHeight * perlinValue;
// 位置のVector3を作成してオブジェクトをインスタンス化します。
Vector3 pos = new Vector3(x, height, z);
InstantiateFieldParts(pos);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment