예제 #1
0
    void Update()
    {
        Color c = text.color;

        c.a        = VectorExtras.Remap(min, max, 0, 1, terrain.GetPlayerDistance());
        text.color = c;
    }
예제 #2
0
 void AddPath()
 {
     for (int i = 0; i < segmentsPerChunk; i++)
     {
         int     ind   = i + overallIndex;
         float   noise = Perlin1D(ind, pathNoiseScale, pathNoiseOctaves, pathNoisePersistence, pathNoiseLacunarity);
         Vector2 point;
         float   noiseFactor = VectorExtras.Remap(0, 100, 0, 1, ind);
         point = Vector2.down * ind * segmentLength + (Vector2.right * noise * noiseFactor);
         path.Add(point);
     }
     overallIndex += segmentsPerChunk;
 }
예제 #3
0
    public void UpdateTerrain()
    {
        bottomPoints.Clear();
        topPoints.Clear();

        float pathLength = 0;

        for (int i = 1; i < path.Count; i++)
        {
            Vector2 segment = path[i] - path[i - 1];
            Vector2 perp    = Vector2.Perpendicular(segment).normalized;

            Vector2 startPerpCutoff = perp;
            if (i > 1)
            {
                Vector2 prevSegment = path[i - 1] - path[i - 2];
                Vector2 prevPerp    = Vector2.Perpendicular(prevSegment).normalized;
                startPerpCutoff = ((startPerpCutoff + prevPerp) / 2).normalized;
            }

            Vector2 endPerpCutoff = perp;
            if (i < path.Count - 1)
            {
                Vector2 nextSegment = path[i + 1] - path[i];
                Vector2 nextPerp    = Vector2.Perpendicular(nextSegment).normalized;
                endPerpCutoff = ((endPerpCutoff + nextPerp) / 2).normalized;
            }

            // Debug.DrawLine(path[i - 1], path[i - 1] + startPerpCutoff * 100, Color.magenta);
            // Debug.DrawLine(path[i], path[i] + endPerpCutoff * 100, Color.cyan);

            for (int j = 0; j < segment.magnitude; j += terrainPointDensity)
            {
                Vector2 point = Vector2.Lerp(path[i - 1], path[i], j / segment.magnitude);

                float sample      = previousChunksDistance + pathLength + Vector2.Distance(path[i - 1], point);
                float bottomNoise = Perlin1D(sample, terrainNoiseScale, terrainNoiseOctaves, terrainNoisePersistence, terrainNoiseLacunarity, 0);
                float topNoise    = Perlin1D(sample, terrainNoiseScale, terrainNoiseOctaves, terrainNoisePersistence, terrainNoiseLacunarity, 100);

                float caveWidth = VectorExtras.Remap(0, distanceToMinCaveWidth, startingCaveWidth, minCaveWidth, sample);

                Vector2 bottomPoint = point - ((perp * caveWidth) + (perp * bottomNoise));
                Vector2 topPoint    = point + ((perp * caveWidth) + (perp * topNoise));

                if (!IsLeft(path[i - 1], path[i - 1] + startPerpCutoff, bottomPoint) && IsLeft(path[i], path[i] + endPerpCutoff, bottomPoint))
                {
                    bottomPoints.Add(bottomPoint);
                }
                if (!IsLeft(path[i - 1], path[i - 1] + startPerpCutoff, topPoint) && IsLeft(path[i], path[i] + endPerpCutoff, topPoint))
                {
                    topPoints.Add(topPoint);
                }
            }

            pathLength += segment.magnitude;
        }

        float skirtPadding = 3000;

        topPoints.Insert(0, topPoints[0] + Vector2.right * skirtPadding);
        topPoints.Add(topPoints[topPoints.Count - 1] + Vector2.down * skirtPadding);
        topPoints.Add(topPoints[topPoints.Count - 1] + Vector2.right * skirtPadding);

        bottomPoints.Insert(0, bottomPoints[0] + Vector2.left * skirtPadding);
        bottomPoints.Add(bottomPoints[bottomPoints.Count - 1] + Vector2.down * skirtPadding);
        bottomPoints.Add(bottomPoints[bottomPoints.Count - 1] + Vector2.left * skirtPadding);

        if (Application.isPlaying)
        {
            topSection.UpdateSpline(topPoints);
            bottomSection.UpdateSpline(bottomPoints);
        }
    }