Random platform Generator
Hello, Im trying to create a random platform generator on which a character is supposed to jump higher and higher up on. but whenever i generate my map some platforms are further away or too close for a possible jump. Im wondering if anybody can help me with this
Here is my code:
public GameObject platform;
// calls on initiation
void Start()
{
RandomMapBuilder();
}
// Random map builder
void RandomMapBuilder()
{
// Spawn spawns for zone 1
for (int i = 0; i < 20; i++)
{
// Creates positions for all the ground/ platforms to spawn
Vector3 SpawnPosition = new Vector3(Random.Range(-10, 10), Random.Range(0, 100), 0);
Instantiate(platform, SpawnPosition, Quaternion.identity);
}
}
Answer by EmersonGS · Sep 14, 2016 at 11:43 PM
When you are placing your platforms you need to keep in mind how high your player unit can jump. What it seems like here is that you need a very specific random range, instead of applying the random directly to the position you should add it onto the last platforms position so it turns out to be newplatform.transform.position(randY+lastPlatform.y) etc
This means your platforms will stay a fairly consistent height from one another
Your answer
Follow this Question
Related Questions
Randoming in a Randomed variable 1 Answer
Instantiate objects in given range 1 Answer
Random.Range code problem or problem with Unity? 1 Answer
Random Generation problem GameObject 0 Answers
how to load random / shuffle scene without repeating current scene? (when button next level pressed) 0 Answers