- Home /
Question by
costin88boss · Apr 30, 2020 at 07:05 PM ·
2dterraingenerator
random height 2d Generator
so, i've made a terrain generator which only gets object to duplicate, and move to a point (i don't want it infinite though). the problem is, it will only move flat, and i want it to sometimes make hills, flat, like minecraft generation but in 2d and no caves.
public GameObject thePlatform;
public Transform generation;
public float distanceBetween;
private float platformWidth;
//
void Start()
{
platformWidth = thePlatform.GetComponent<BoxCollider2D>().size.x;
}
void Update()
{
if(transform.position.x < generation.position.x)
{
transform.position = new Vector3(transform.position.x + platformWidth + distanceBetween, transform.position.y, transform.position.z);
Instantiate(thePlatform, transform.position, transform.rotation);
}
}
Comment
Hi, i suggest you to take a look at "Perlin Noise", there are many tutorials on youtube :)
Your answer
![](https://koobas.hobune.stream/wayback/20220612232933im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Code Loops Indefinitely 1 Answer
Anyone got a Voxel generator I can use? 0 Answers
2D Default terrain editor 0 Answers
Ferr2D Terrain Problem when i instantiate from resources 0 Answers
Terraria / Starbound Style Lighting 3 Answers