G'day all,
I've found a snippet in k1lly0u's Rad Pockets plugin which likely has most of the code I want:
I'm just unsure as to what the -600f and such are useful for - can I check the mapsize as a decimal and compare it to passed decimal coordinate values?Code:private Vector3 getRandomPos() { float mapSize = (TerrainMeta.Size.x / 2) - 600f; float randomX = UnityEngine.Random.Range(-mapSize, mapSize); float randomY = UnityEngine.Random.Range(-mapSize, mapSize); Vector3 pos = new Vector3(randomX, 0, randomY); Vector3 targetPos = getGroundPosition(pos); return targetPos; } static Vector3 getGroundPosition(Vector3 sourcePos) // credit Wulf & Nogrod { RaycastHit hitInfo; if (Physics.Raycast(sourcePos, Vector3.down, out hitInfo, GROUND_MASKS)) { sourcePos.y = hitInfo.point.y; } sourcePos.y = Mathf.Max(sourcePos.y, TerrainMeta.HeightMap.GetHeight(sourcePos)); return sourcePos; }
I'm hoping to have a function which can accept both an x,y,z input (where those are all integers/decimals) and a player.transform.position. Obviously the position one should always be a valid map location, just need to ensure I check the manually entered coords for out-of-bounds values.
Thank you for any assistance
[DOUBLEPOST=1451125622][/DOUBLEPOST]Ah, may have my answer... Convert.ToInt16(TerrainMeta.Size.x) should return an int I can work with![]()
Checking that a Vector3 is a valid map position (within coords)
Discussion in 'Rust Development' started by Gliktch, Dec 26, 2015.
-
He probably subtracted 600f from the true map size because the true map size takes the ocean around the map into account.
-
Thank you, yes, that makes sense. For my purposes I'd probably take off a lot less, but if that's all it was, then at least I know I'm not missing anything else important
