Generating a random coordinate on map?
Discussion in 'Rust Development' started by jackcat, Mar 13, 2018.
-
new Vector3(Oxide.Core.Random.Range(-worldSize^2/2, worldSize^2/2), 1000, Oxide.Core.Random.Range(-worldSize^2/2, worldSize^2/2)).
Then raycast from your Vector3, to Vector3.Down, to find terrain point and spawn it here.
It can be underwater, but you check it, if point.y<0, then make again while point .y >0 -
You can use TerrainMeta.HeightMap.GetHeight(position) to get the terrain height (y) for a position, then use WaterLevel.Test(position) to check for water. You don't have to deal with a raycast this way, and I believe WaterLevel.Test also detects rivers (not just ocean).
-
Alright thanks guys
-
How exactly do I use the WaterLevel.Test though?
-
-
Got it working using
Code:bool wtest = WaterLevel.Test(pos); if (wtest == false) { Do stuff } else return;
-
How can I make it so the random location I generate isn't near monuments?
-
Code:
Vector3 pos = new Vector3(); // your random position bool isNearMonument = false; foreach (MonumentInfo monument in UnityEngine.Object.FindObjectsOfType<MonumentInfo>().OrderBy(o => o.name)) { float distance = Vector3.Distance(pos, monument.transform.position); if (distance < 10) { isNearMonument = true; break; } } if (isNearMonument) { // TODO try another position }
-
Thanks dude
Is there also a way to avoid spawning near cliffs?Last edited by a moderator: Mar 21, 2018 -
Solved.