sometime the spawn is over the water not to far out from land what am i missing?
Code:Vector3 GetRandomVector() { float max = ConVar.Server.worldsize / 2; float x = UnityEngine.Random.Range(max * (-1), max); float y = UnityEngine.Random.Range(200, 300); float z = UnityEngine.Random.Range(max * (-1), max); object terrainHeight = GetTerrainHeight(new Vector3(x, 300, z)); if (terrainHeight is Vector3) return (Vector3) terrainHeight; else return new Vector3(x, y, z); } private static LayerMask GROUND_MASKS = LayerMask.GetMask("Terrain", "World", "Construction"); object GetTerrainHeight(Vector3 location) { float distanceToWater = location.y - TerrainMeta.WaterMap.GetHeight(location); RaycastHit rayHit; if (Physics.Raycast(location, Vector3.down, out rayHit, GROUND_MASKS)) { return rayHit.point; } return false; }
GetRandomVector returns over water sometimes
Discussion in 'Rust Development' started by Ts3hosting, Feb 13, 2017.
-
another thing i noticed is if vector3 is close to a rad town you do not get ground level
Last edited by a moderator: Feb 13, 2017 -
You need to do something with the distanceToWater variable you created.
float waterDistance(Vector3 location)
{
return (TerrainMeta.HeightMap.GetHeight(location) - TerrainMeta.WaterMap.GetHeight(location) );
} -
If you're just trying to determine if your point is is over water, you can use this:
Code:// Vector3 position, returns true if terrain at coordinate (x, z) is under water WaterLevel.Test(position);
Code:Vector3 SelectTarget() { // random select (x, z) target between (-1,-1) and (+1,+1) Vector3 target = new Vector3(UnityEngine.Random.Range(-1f,1f), 0f, UnityEngine.Random.Range(-1f,1f)); // scale position to world size target *= (ConVar.Server.worldsize-1)/2; // get terrain y position at target position float height = TerrainMeta.HeightMap.GetHeight(target); Vector3 pos = new Vector3(target.x, height, target.z); // check for water at position if (WaterLevel.Test(pos)) return SelectTarget(); // over water, recurse else return pos; }
-
removed..seen later totally outdated thread
@carny666
>> OxideMod.org rules and terms of service | Oxide
Posting Messages
8) Members are asked not to resurrect threads older than one month without good reason.Last edited by a moderator: Oct 28, 2017 -