1. 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;
            }
     
  2. 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
  3. You need to do something with the distanceToWater variable you created.

    float waterDistance(Vector3 location)
    {
    return (TerrainMeta.HeightMap.GetHeight(location) - TerrainMeta.WaterMap.GetHeight(location) );
    }
     
  4. 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);
    A simple procedure I've used to get a random point on the terrain, excluding water, without raycasting (should fix your radtown issue):
    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;
    }
     
  5. Last edited by a moderator: Oct 28, 2017
  6. Oops - I didn't notice this thread was necro'd...