Beispiel #1
0
    private IEnumerator ChangeWaterLevel()
    {
        float from = BasePosition.y - transform.position.y;
        float to   = levels[_targetWaterLevel];

        float distance = Mathfs.Abs(from - to);

        if (distance == 0)
        {
            yield break;
        }

        float moveDuration = distance / speed;

        float fractionTimeElapsed = 0.0f;

        while (fractionTimeElapsed < 1.0f)
        {
            fractionTimeElapsed += Time.deltaTime / moveDuration;
            float t = Mathfs.Smoother01(fractionTimeElapsed);

            transform.position = new Vector3(
                BasePosition.x,
                BasePosition.y - Mathfs.Lerp(from, to, t),
                BasePosition.z);

            yield return(new WaitForEndOfFrame());
        }

        _currentWaterLevel = _targetWaterLevel;
        Debug.Log($"Water level is now {_currentWaterLevel}");
    }
Beispiel #2
0
    void CalculateTangents(Vector3 clownPoint, Vector3 unicornPoint, out Vector3 tangentA, out Vector3 tangentB)
    {
        float distance = Vector3.Distance(clownPoint, unicornPoint);

        if (distance > maxDistance)
        {
            // This should technically never happen, but I'm handling it just in case.
            // We are further away than we should be and the unicorn should have popped to us.
            tangentA = clownPoint;
            tangentB = unicornPoint;
        }
        else
        {
            // @NOTE: Reader Beware: Even I don't know what this is doing geometrically, and I wrote the damn thing.
            float remainingDistance = maxDistance - distance;
            float triangleT         = remainingDistance / maxDistance;

            Vector3 pointC = (clownPoint + unicornPoint) / 2.0f + (Vector3.down * remainingDistance);

            float minPoint = Mathfs.Min(unicornPoint.y, clownPoint.y);
            float saggiest = minPoint - maximumSag;

            tangentA = Vector3.Lerp(clownPoint, pointC, triangleT + (triangleT * remainingDistance));
            tangentB = unicornPoint + (unicornPoint - pointC) * -(Mathfs.Abs((saggiest - tangentA.y).AtMost(0.0f)));

            tangentA.y = Mathfs.Max(tangentA.y, saggiest);
            tangentB.y = Mathfs.Max(tangentB.y, saggiest);
        }
    }
    static float Chebyshev(Vector3 a, Vector3 b)
    {
        var dist = a - b;

        return(Mathfs.Max(Mathfs.Abs(dist.x),
                          Mathfs.Abs(dist.y),
                          Mathfs.Abs(dist.z)));
    }
    private (float, float, float) BlendCameras(float a, float b, float t)
    {
        float smoothT   = Mathfs.Smooth01(Mathfs.InverseLerpClamped(a, b, t)) * 2.0f;
        float firstCam  = Mathfs.Clamp01(1 - smoothT);
        float blendCam  = Mathfs.Max(1 - Mathfs.Abs(1 - smoothT), 0);
        float secondCam = Mathfs.Clamp01(smoothT - 1);

        var result = (firstCam, blendCam, secondCam);

        return(result);
    }
Beispiel #5
0
    private float KeyboardControls()
    {
        if (Mathfs.Abs(currentHorizAngle - targetHorizAngle) < 5.0f)
        {
            //@TODO: Temporary hard-coded AWFULNESS. Clean this up when designers know how they want the camera to be.
            var requestedTurn = 0.0f;
            requestedTurn += Input.GetKeyDown(KeyCode.Q) ? -90.0f : 0.0f;
            requestedTurn += Input.GetKeyDown(KeyCode.E) ? 90.0f : 0.0f;

            targetHorizAngle += requestedTurn;
        }

        return(Mathfs.SmoothDamp(currentHorizAngle, targetHorizAngle, ref horizVel, RotationDelay, RotateSpeed));
    }
 static float Rectilinear(Vector3 a, Vector3 b)
 {
     return(Mathfs.Abs(a.x - b.x)
            + Mathfs.Abs(a.y - b.y)
            + Mathfs.Abs(a.z - b.z));
 }
 public static float Magnitude(this float v) => Mathfs.Abs(v);
 public static float Abs(this float v) => Mathfs.Abs(v);