示例#1
0
    private void RecalculateBorders()
    {
        Vector3 border = new Vector3(_borderSize, 0f, _borderSize);

        _borderConfig                 = new BorderConfig();
        _borderConfig.Size            = _borderSize;
        _borderConfig.WindSpeed       = _borderWindSpeed;
        _borderConfig.WindPow         = _borderWindPow;
        _borderConfig.BottomLeftInner = _borderBottomLeft + border;
        _borderConfig.TopRightInner   = _borderTopRight - border;
        _borderConfig.SizeInverse     = 1f / _borderSize; // Optimizes out the division
    }
示例#2
0
    private static Vector3 GetBorderWindVelocity(BorderConfig border, Vector3 position)
    {
        // If position is near world borders, add wind that pushes back

        //if (position.x < _borderBottomLeft.x + _borderSize) {
        //  windVelocity.x += (_borderSize - (position.x - _borderBottomLeft.x)) / _borderSize * _borderWindSpeed;
        //}

        // Below is an optimized version of the above, for all four borders

        Vector3 windVelocity = new Vector3();

        const float verticalScale = 0.5f;

        if (position.x < border.BottomLeftInner.x)
        {
            float correction = (position.x - border.BottomLeftInner.x) * -border.SizeInverse;
            correction      = Mathf.Pow(correction, border.WindPow) * border.WindSpeed;
            windVelocity.x += correction;
            windVelocity.y += Mathf.Abs(correction) * verticalScale;
        }
        if (position.z < border.BottomLeftInner.z)
        {
            float correction = (position.z - border.BottomLeftInner.z) * -border.SizeInverse;
            correction      = Mathf.Pow(correction, border.WindPow) * border.WindSpeed;
            windVelocity.z += correction;
            windVelocity.y += Mathf.Abs(correction) * verticalScale;
        }
        if (position.x > border.TopRightInner.x)
        {
            float correction = ((position.x - border.TopRightInner.x)) * border.SizeInverse;
            correction      = Mathf.Pow(correction, border.WindPow) * border.WindSpeed;
            windVelocity.x -= correction;
            windVelocity.y += Mathf.Abs(correction) * verticalScale;
        }
        if (position.z > border.TopRightInner.z)
        {
            float correction = ((position.z - border.TopRightInner.z)) * border.SizeInverse;
            correction      = Mathf.Pow(correction, border.WindPow) * border.WindSpeed;
            windVelocity.z -= correction;
            windVelocity.y += Mathf.Abs(correction) * verticalScale;
        }
        return(windVelocity);
    }