Unity¤Ë´ØÏ¢¤¹¤ëµ­»ö¤Ç¤¹

¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤È¤Ï


¡¡¥²¡¼¥à¤Ë¤ª¤±¤ë¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤È¤Ï¡¢Íð¿ô½èÍý¤Î£±¤Ä¤Ç¤¹¡£
´°Á´¤ÊÍð¿ô¤Ç¤Ï¤Ê¤¯¤Æ¡¢»ØÄꤷ¤¿Ãͤò¥Ù¡¼¥¹¤Ë¡¢¤Ê¤À¤é¤«¤ÊÍð¿ôÃͤòÀ¸À®¤·¤Þ¤¹¡£

¡¡Î㤨¤Ð¡¢¥é¥ó¥À¥à¤ÊÃÏ·Á¤òÀ¸À®¤·¤¿¤¤¤è¤¦¤Ê¾ì¹ç¡¢´°Á´¤ÊÍð¿ô¤Ë¤·¤Æ¤·¤Þ¤¦¤È¡¢ÃÏ·Á¤ÎÁ°¸å¤Îµ¯Éú¤ËϢ³À­¤äµ¬Â§À­¤¬¸«¤¨¤Ê¤¤¡¢ÉÔ¼«Á³¤Êºî¤ê¤Ë¤Ê¤ê¤¬¤Á¤Ç¤¹¡£
¤³¤¦¤¤¤Ã¤¿Éôʬ¤Ë¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤òÍøÍѤ¹¤ë¤³¤È¤Ç¡¢ÃÏ·Á¤ÎÁ°¸å¤Î·Ò¤¬¤ê¤òÈ¿±Ç¤·¤¿Íð¿ô¤òÍøÍѤ·¤Æ¡¢¼«Á³¤Ê¤·Á¤Ë¸«¤¨¤ëÃÏ·Á¤òºîÀ®¤¹¤ë¡¢¤È¤¤¤Ã¤¿¤³¤È¤¬²Äǽ¤Ç¤¹¡£

¡¡Æ±Íͤιͤ¨¤Ë¤è¤ê¡¢¥¨¥Õ¥§¥¯¥È¤ä¥¢¥Ë¥á¡¼¥·¥ç¥ó¤Ê¤É¡¢ÍøÍÑÊýË¡¤Ï¿´ô¤ËÅϤê¤Þ¤¹¡£

¡¡²òÀ⤵¤ì¤Æ¤¤¤ë¥µ¥¤¥È¤â¿¤¤¤Î¤Ç¡¢¤¼¤Ò³Ø½¬¤·¤Æ¤ª¤­¤Þ¤·¤ç¤¦¡£

Unity ¸ø¼°¥¹¥¯¥ê¥×¥È¥ê¥Õ¥¡¥ì¥ó¥¹
Mathf.PerlinNoise
https://docs.unity3d.com/ja/current/ScriptReferenc...
note
k1togami ÍÍ
[Unity][C#Script] Íð¿ô¤òÀ©¤¹¤ë¤â¤Î¤Ï¡¢¥²¡¼¥àÀ©ºî¤òÀ©¤¹¤ë¡£¥Ñ¡¼¥ê¥ó¥Î¥¤¥ºÃÏ·Á¤òÀ©¤·¤Æ¤·¤Æ¤ß¤ëÊÔ
¤Í¤³¤¸¤ã¤é¥·¥Æ¥£ ÍÍ
¡ÚUnity¡Û¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤ÇÍÍ¡¹¤Êʪ¤òÍɤ餹
https://nekojara.city/unity-perlin-noise-shake
kan ¤Î¥á¥âÄ¢
¥Ñ¡¼¥ê¥ó¥Î¥¤¥º(PerlinNoise)¤È¤Ï¡ÚUnity¡Û¡Ú¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¡Û
https://kan-kikuchi.hatenablog.com/entry/What_is_P...


Mathf.PerlinNoise() ¥á¥½¥Ã¥É


¡¡Mathf ¥¯¥é¥¹¤Ë¤Ï PerlinNoise(float x, float y) ¤È¤¤¤¦¥á¥½¥Ã¥É¤¬¤¢¤ê¤Þ¤¹¡£
¤³¤ì¤Ï¡¢2D¤Î¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤òÀ¸À®¤¹¤ë¤¿¤á¤Ë»È¤ï¤ì¤Þ¤¹¡£

float noiseValue = Mathf.PerlinNoise(x, y);

¡¡¤³¤Î¥á¥½¥Ã¥É¤Ï x ¤È y ¤Î2¤Ä¤ÎºÂɸ¤ò°ú¿ô¤Ë¼è¤ê¡¢¤½¤ì¤ËÂбþ¤¹¤ë¥Î¥¤¥ºÃÍ¡Ê0¤«¤é1¤Î´Ö¤ÎÃ͡ˤòÊÖ¤·¤Þ¤¹¡£

¡¡¤³¤Î¤è¤¦¤ÊÆÃħ¤«¤é¡¢¥²¡¼¥à¤Ç¼«Á³¤ÊÃÏ·ÁÀ¸À®¤ä¥é¥ó¥À¥à¤Ê¥¨¥Õ¥§¥¯¥È¥Ñ¥¿¡¼¥ó¤òºîÀ®¤¹¤ëºÝ¤Ë»ÈÍѤµ¤ì¤ë¤³¤È¤¬Â¿¤¤¤Ç¤¹¡£


³èÍÑÊýË¡¡¡¡¼ÃÏ·ÁÀ¸À®¡¼


¡¡¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤ò»È¤Ã¤¿ÃÏ·ÁÀ¸À®¤Ï¡¢¥é¥ó¥À¥à¤Ê¥Î¥¤¥º¤ò»È¤Ã¤Æ³ê¤é¤«¤Ç¼«Á³¤Ê¥Ñ¥¿¡¼¥ó¤òºî¤ê½Ð¤¹¤¿¤á¤ËÍøÍѤµ¤ì¤Þ¤¹¡£
Ä̾ï¤Î¥é¥ó¥À¥à¥Î¥¤¥º¤Ï¡¢Ãͤ¬´°Á´¤Ë¥é¥ó¥À¥à¤Ê¤¿¤á¡¢Ï¢Â³¤¹¤ë¥Ô¥¯¥»¥ë¤ä¥Ý¥¤¥ó¥È¤Î´Ö¤ËµÞ¤ÊÊѲ½¤¬¤¢¤ê¡¢¼«Á³¤Ë¤Ï¸«¤¨¤Þ¤»¤ó¡£
¤Ç¤¹¤¬¡¢¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤ÏÎÙÀܤ¹¤ëÃͤ¬³ê¤é¤«¤ËÊѲ½¤¹¤ë¤¿¤á¡¢¼«Á³³¦¤Ë¸«¤é¤ì¤ë¤è¤¦¤ÊϢ³Ū¤Ê¥Ñ¥¿¡¼¥ó¤òÀ¸À®¤Ç¤­¤Þ¤¹¡£


¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤òÍѤ¤¤¿ÃÏ·ÁÀ¸À®¤Î¼ê½ç

£±¡¥¥°¥ê¥Ã¥É¤ËÂФ¹¤ë¥Î¥¤¥º¤ÎŬÍÑ


¡¡2DÃÏ·Á¤òÀ¸À®¤¹¤ë¤¿¤á¤Ë¤Ï¡¢2D¥°¥ê¥Ã¥É¤òÀßÄꤷ¡¢¤½¤Î³Æ¥Ý¥¤¥ó¥È¤Ç¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤ò»ÈÍѤ·¤Þ¤¹¡£
Î㤨¤Ð¡¢100x100¤ÎÃÏ·Á¥°¥ê¥Ã¥É¤¬¤¢¤ë¾ì¹ç¡¢³Æ¥°¥ê¥Ã¥É¥Ý¥¤¥ó¥È¤ËÂФ·¤Æ Mathf.PerlinNoise(x, y) ¤ò»È¤¤¡¢¤½¤Î·ë²Ì¤ÎÃͤòÃÏ·Á¤Î¹â¤µ¤Ë¥Þ¥Ã¥Ô¥ó¥°¤·¤Þ¤¹¡£

int width = 100;
int height = 100;
float scale = 10.0f;

for (int x = 0; x < width; x++) {
    for (int y = 0; y < height; y++) {
        // ¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤Î·×»»
        float perlinValue = Mathf.PerlinNoise(x * scale, y * scale);
        
        // ¥Î¥¤¥ºÃͤò¹â¤µ¤Ë¥Þ¥Ã¥Ô¥ó¥°
        float terrainHeight = Mathf.Lerp(0, maxHeight, perlinValue);

        // ¤³¤³¤ÇÃÏ·Á¥á¥Ã¥·¥å¤ä¥¿¥¤¥ë¥Þ¥Ã¥×¤Î¹â¤µ¤òÀßÄê
    }
}

¡¡x * scale ¤ä y * scale ¤Ï¡¢¥Î¥¤¥º¥Ñ¥¿¡¼¥ó¤Î¥¹¥±¡¼¥ë¤òÄ´À°¤¹¤ë¤¿¤á¤Ç¤¹¡£
¥¹¥±¡¼¥ë¤ò¾®¤µ¤¯¤¹¤ë¤È¡¢¥Î¥¤¥º¤ÎÊѲ½¤¬µÞ¤Ë¤Ê¤ê¡¢¥¹¥±¡¼¥ë¤òÂ礭¤¯¤¹¤ë¤È¡¢³ê¤é¤«¤ÊÊѲ½¤¬ÆÀ¤é¤ì¤Þ¤¹¡£

¡¡Mathf.Lerp(0, maxHeight, perlinValue) ¤Ç¤Ï¡¢0¤«¤émaxHeight¤ÎÈÏ°ÏÆâ¤ÇÃÏ·Á¤Î¹â¤µ¤ò¥Î¥¤¥ºÃͤ˴ð¤Å¤¤¤ÆÀßÄꤷ¤Æ¤¤¤Þ¤¹¡£


£²¡¥¥¹¥à¡¼¥º¤ÇϢ³Ū¤ÊÃÏ·Á


¡¡¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤ÎÆÃħ¤Ï¡¢Ï¢Â³¤·¤¿ÃͤòÍ¿¤¨¤ë¤ÈÎÙÀܤ¹¤ë¥Î¥¤¥ºÃͤ¬³ê¤é¤«¤ËÊѲ½¤·¤Þ¤¹¡£
¤½¤Î¤¿¤áµÞ·ã¤Ê¹â¤µ¤ÎÊѲ½¤¬¤Ê¤¯¡¢Ï¢Â³Åª¤Ç¼«Á³¤Ê·Á¾õ¤¬À¸À®¤µ¤ì¤Þ¤¹¡£¤³¤ì¤Ë¤è¤ê¡¢»³¤äë¤Î¤è¤¦¤Ê³ê¤é¤«¤ÊÃÏ·Á¤¬ºî¤ê¤ä¤¹¤¯¤Ê¤ê¤Þ¤¹¡£


£³¡¥¥ª¥¯¥¿¡¼¥Ö¤ÎÄɲÃ


¡¡¤è¤êÊ£»¨¤Ç¥ê¥¢¥ë¤ÊÃÏ·Á¤òºî¤ë¤¿¤á¤Ë¡¢°Û¤Ê¤ë¥¹¥±¡¼¥ë¤ä¶¯ÅÙ¤ò»ý¤Ä¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤òÊ£¿ô½Å¤Í¤ë¤³¤È¤¬¤è¤¯¤¢¤ê¤Þ¤¹¡£
¤³¤ì¤ò¡Ö¥ª¥¯¥¿¡¼¥Ö¡×¤È¸Æ¤Ó¤Þ¤¹¡£

¡¡Äã¼þÇȥΥ¤¥º¡ÊÂ礭¤ÊÃÏ·Á¡Ë¤È¹â¼þÇȥΥ¤¥º¡Ê¾®¤µ¤ÊÃÏ·Á¤ÎºÙ¤«¤¤¥Ç¥£¥Æ¡¼¥ë¡Ë¤òÁȤ߹ç¤ï¤»¤ë¤³¤È¤Ç¡¢»³Ì®¤ä¾®¤µ¤ÊµÖ¤Ê¤É¡¢¼«Á³³¦¤Ç¸«¤é¤ì¤ë¤è¤¦¤ÊÊ£»¨¤ÊÃÏ·Á¤òºî¤ì¤Þ¤¹¡£

float GeneratePerlinNoise(float x, float y, int octaves, float persistence) {
    float total = 0;
    float frequency = 1;
    float amplitude = 1;
    float maxValue = 0;

    for (int i = 0; i < octaves; i++) {
        total += Mathf.PerlinNoise(x * frequency, y * frequency) * amplitude;

        maxValue += amplitude;
        amplitude *= persistence;
        frequency *= 2;
    }

    return total / maxValue;
}

¡¡octaves¡§¥Î¥¤¥º¤ò½Å¤Í¤ë²ó¿ô¡£¤³¤ì¤Ë¤è¤êºÙ¤«¤¤¥Ç¥£¥Æ¡¼¥ë¤¬Áý¤¨¤ë¡£
¡¡persistence¡§³Æ¥ª¥¯¥¿¡¼¥Ö¤Î¿¶Éý¤ò¸º¾¯¤µ¤»¤ë·¸¿ô¡£¤³¤ì¤Ë¤è¤ê¹â¼þÇȥΥ¤¥º¤¬¼¡Âè¤Ë¾®¤µ¤¯¤Ê¤ë¡£


£´¡¥¹âÅ٤Υޥåԥó¥°


¡¡¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤«¤éÆÀ¤é¤ì¤¿Ãͤò´ð¤Ë¡¢ÃÏ·Á¤Î¼ïÎà¡Ê³¤¡¢Ê¿ÃÏ¡¢»³¤Ê¤É¡Ë¤ò·èÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£
Î㤨¤Ð¡¢¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤ÎÃͤ¬0.3°Ê²¼¤Ê¤é¡Ö¿å¡×¡¢0.3¡Á0.6¤Ê¤é¡ÖÊ¿Ãϡס¢0.6°Ê¾å¤Ê¤é¡Ö»³¡×¤È¤¤¤Ã¤¿¶ñ¹ç¤Ë·èÄꤹ¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

if (perlinValue < 0.3f) {
    // ¿å
} else if (perlinValue < 0.6f) {
    // Ê¿ÃÏ
} else {
    // »³
}


¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤ò»È¤Ã¤¿¼«Á³¤Ê¥Ñ¥¿¡¼¥ó¤ÎÆÃħ¤Î¤Þ¤È¤á


¡¡Ãͤ¬³ê¤é¤«¤ËÊѤï¤ë¤¿¤á¡¢µÞ·ã¤Ê¹â¤µ¤ÎÊѲ½¤¬¤Ê¤¤¼«Á³¤ÊÃÏ·Á¤¬À¸À®¤µ¤ì¤Þ¤¹¡£

¡¡¥¹¥±¡¼¥ë¡¢¥ª¥¯¥¿¡¼¥Ö¡¢¿¶Éý¤Ê¤É¤Î¥Ñ¥é¥á¡¼¥¿¤òÄ´À°¤¹¤ë¤³¤È¤Ç¡¢¤µ¤Þ¤¶¤Þ¤Ê¥Ñ¥¿¡¼¥ó¤òÀ¸À®¤Ç¤­¤Þ¤¹¡£
¾®¤µ¤Êµ¯Éú¤Î¿¤¤ÃÏ·Á¤ä¡¢¤æ¤ë¤ä¤«¤ÊµÖÎÍÃÏÂӤʤɡ¢¤¤¤í¤¤¤í¤ÊÃÏ·Á¤¬ºîÀ®²Äǽ¤Ç¤¹¡£

¡¡¤³¤Î¤è¤¦¤Ë¡¢¥Ñ¡¼¥ê¥ó¥Î¥¤¥º¤òŬÍѤ¹¤ë¤³¤È¤Ç¡¢¥²¡¼¥à¤ä¥·¥ß¥å¥ì¡¼¥·¥ç¥ó¤Ç¤è¤¯¸«¤é¤ì¤ë¡¢¼«Á³¤Ç³ê¤é¤«¤ÊÃÏ·Á¤ä¥Ñ¥¿¡¼¥ó¤òÀ¸À®¤¹¤ë¤³¤È¤¬¤Ç¤­¤Þ¤¹¡£

¥³¥á¥ó¥È¤ò¤«¤¯


¡Öhttp://¡×¤ò´Þ¤àÅê¹Æ¤Ï¶Ø»ß¤µ¤ì¤Æ¤¤¤Þ¤¹¡£

ÍøÍѵ¬Ìó¤ò¤´³Îǧ¤Î¤¦¤¨¤´µ­Æþ²¼¤µ¤¤

Menu


´ðÁÃ

µ»½Ñ/Ãμ±(¼ÂÁõÎã)

3D¥¢¥¯¥·¥ç¥ó¥²¡¼¥à

2D¤ª¤Ï¤¸¤­¥²¡¼¥à(ȯŸÊÔ)

2D¶¯À©²£¥¹¥¯¥í¡¼¥ë¥¢¥¯¥·¥ç¥ó(ȯŸÊÔ)

2D¥¿¥Ã¥×¥·¥å¡¼¥Æ¥£¥ó¥°(³ÈÄ¥ÊÔ)

¥ì¡¼¥¹¥²¡¼¥à(È´¿è)

2DÊüÃÖ¥²¡¼¥à(ȯŸÊÔ)

3D¥ì¡¼¥ë¥¬¥ó¥·¥å¡¼¥Æ¥£¥ó¥°(±þÍÑÊÔ)

3Dæ½Ð¥²¡¼¥à(È´¿è)

2D¥ê¥¢¥ë¥¿¥¤¥à¥¹¥È¥é¥Æ¥¸¡¼

3D¥¿¥Ã¥×¥¢¥¯¥·¥ç¥ó(NavMeshAgent »ÈÍÑ)

2D¥È¥Ã¥×¥Ó¥å¡¼¥¢¥¯¥·¥ç¥ó(¥«¥¨¥ë¤Î°Ù¤Ë¡Á¡¢¥Ü¥³¥¹¥«¥¦¥©¡¼¥ºÉ÷)

VideoPlayer ¥¤¥Ù¥ó¥ÈϢư¤Î¼ÂÁõÎã

VideoPlayer ¥ê¥¹¥ÈÆ⤫¤é¥à¡¼¥Ó¡¼ºÆÀ¸¤Î¼ÂÁõÎã(ȯŸ)

AR ²èÁüÉÕ¤­¥ª¥Ö¥¸¥§¥¯¥ÈÀ¸À®¤Î¼ÂÁõÎã

AR ¥ê¥¹¥ÈÆ⤫¤éÀ¸À®¤Î¼ÂÁõÎã(ȯŸ)

2D¥È¥Ã¥×¥Ó¥å¡¼¥¢¥¯¥·¥ç¥ó(¥µ¥Ð¥¤¥Ð¡¼É÷)

private



¤³¤Î¥µ¥¤¥ÈÆâ¤ÎºîÉʤϥæ¥Ë¥Æ¥£¤Á¤ã¤ó¥é¥¤¥»¥ó¥¹¾ò¹à¤Î¸µ¤ËÄ󶡤µ¤ì¤Æ¤¤¤Þ¤¹¡£

´ÉÍý¿Í/Éû´ÉÍý¿Í¤Î¤ßÊÔ½¸¤Ç¤­¤Þ¤¹