Create a random Mountain
Hello Community, I wanted to ask, if there is a possibility to create a random mountain at the start of the game. I searched in Google and in this forum, but i couldn't find something i could directly add to the game. I am pretty new here and i am using Unity for just a short time now. Thanks for every help ^^
thats a pretty complicated question yer asking! the easiest way would be to have a bunch of different mountains allready made and have your game pick a random number for which one to spawn during runtime.
Yeah, i think i will go with this solution.
Answer by Graphics_Dev · Mar 14, 2016 at 10:04 PM
Here is a little code I just wrote to do something like this. You assign mountain prefabs to the slots in the script (as many as you want: it's scalable). Next assign your maxs and mins for all axis. Hope this helps ;)
using UnityEngine;
using System.Collections;
public class MountainPlacer : MonoBehaviour
{
public GameObject[] mountains;
public int randomMountain;
public float xPositionMax;
public float xPositionMin;
public float yPositionMax;
public float yPositionMin;
public float zPositionMax;
public float zPositionMin;
// Use this for initialization
void Start ()
{
randomMountain = Random.Range (0, mountains.Length);
Instantiate (mountains [randomMountain], new Vector3(Random.Range(xPositionMin,xPositionMax),Random.Range(yPositionMin,yPositionMax),Random.Range(zPositionMin,zPositionMax)), Quaternion.Euler (Vector3.zero));
}
}
Thank you for the fast solution! I think i should really just make some mountains and choose a random one ins$$anonymous$$d of creating a random. Thank you guys for the fast help. Do you still have an idea how it would be possible to make one random? btw, nice script, helped me a lot ^^
well, a common technic for smooth changing ups and downs is using height maps. you would have to look it up to get the details but its basically using a black and white png image and the terrain picks up how dark the pixels are to represent how high the terrain is. i personally would take the approach of creating a random faded texture2D to assign as a height map.
i would start by getting some random locations in your PNG texture for peaks and peak heights. then Loop through all the pixels coloring them based by the distance to the random peaks. it would create a fade effect in your image. its very highly possible but could take much time coding to get your desired affect.
and by the way....cheers to Graphics_Dev's answer!
I don't really understand your comment...what is the difference between "choose a random one" and "creating a random"? Also what do you mean by "how it would be possible to make one random"? Are you talking about a procedurally generated mountain?
Oh yes, sorry i meant a procedurally generated mountain. Now that you say it i see my question was bad formulated. Thanks for beeing that patiently :D
Your answer
Follow this Question
Related Questions
Initiating random camera on start? 2 Answers
Prevent overlap with Random.onUnitSphere 0 Answers
¿Por dónde empezar en Unity? 0 Answers
Access singleton in OnEnable when it's initialized in Awake 3 Answers