Search Unity

Complex Question Regarding 2D Image/Mountains Generation

Discussion in '2D' started by exzizt, Jan 21, 2019.

  1. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    How can I generate at runtime these three green hills you see in the background (code/scripts please)? I want them to be sort of the same height as they already are, with the one in the back being the tallest and the one in the front being the shortest. As the game moves on to the right side of the screen more and more of the mountains will be exposed and they move in a parallax fashion. The mountains are sort of randomly varying but nothing too drastic, and they have the pixel shape they do now.

    upload_2019-1-21_13-12-59.png
     
    Last edited: Jan 22, 2019
  2. hlw

    hlw

    Joined:
    Aug 12, 2017
    Posts:
    250
    I'd do various mountain sprites with different shapes and height, and various sprites of valleys that can lead to another mountain, and just randomly make some mountains pop, then put corresponding valleys in between. You'd need a really big load of valley sprites as the number of mountain increase.

    Otherwise, you could procedurally generate a bezier curve and use it to create a mesh. Then find a way to make it look pixelated.
     
  3. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    I think this is what I need. I don't want so many mountain sprites, procedurally generated stuff would be best. Can you help me implement this?
     
  4. hlw

    hlw

    Joined:
    Aug 12, 2017
    Posts:
    250
    Unfornately, that would take me too much time to do that for you (Mostly because i don't master this subject).

    You need to google stuffs like:
    "Unity bezier curve"
    "Unity Generate mesh at runtime using points" (You could check Triangulator or something)

    Then i guess you'd need to remember your maths class to remember the shapes you can create using mathematical functions, and find a way to randomize it in a way that give you the results you need.

    If you want my opinion, this is too much work for the result it will give you. You should just create a long enough background containing lot of different montains, and loop through it using parallax. As the three layers of mountains will move at different speeds, the player will have difficulties to recognize the pattern (if the Background base sprite is long enough). Dont forget that the begeinning of the very first mountain should correspond to the end of the very last one.

    And as your sprites are rather simple and monocoloured, i guess you can compress them pretty easily and heavily, letting you create big ones with a low impact on performances.
     
  5. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    This is actually what I have implemented currently. Thanks for your help though!
     
  6. WhiteRabbyte

    WhiteRabbyte

    Joined:
    Jan 21, 2019
    Posts:
    2
    I would simply have 3 perlin noise generated textures and just have a falloff map at the desired heights then offsetting would always provide a seamless mountain/valley that is infinite and random, but not random if you backtrack
     
  7. exzizt

    exzizt

    Joined:
    Sep 30, 2017
    Posts:
    78
    Code please. :)