Esempio n. 1
0
    private void ApplyBubbleForces(SoapBubble other)
    {
        if (other == null)
        {
            return;
        }

        var delta    = transform.position - other.transform.position + Random.onUnitSphere * 0.01f;
        var distance = delta.magnitude;

        var totalRadius = (Radius + other.Radius);

        if (distance < totalRadius)
        {
            _rigidbody.AddForce(delta.normalized * _repelForce / distance, _repelForceMode);

            if (other.IsFree && distance < _mergeDistanceThreshold)
            {
                MergeWithBubble(other);
            }
        }
        else
        {
            var surfaceDistance = Mathf.Max(0f, distance - Radius);
            _rigidbody.AddForce(-delta.normalized * _attractForce / surfaceDistance, _attractForceMode);
        }
    }
Esempio n. 2
0
    private void MergeWithBubble(SoapBubble other)
    {
        DOTween.Kill(this);
        transform.DOScale(Radius + other.Radius, 0.1f)
        .SetSpeedBased()
        .SetEase(Ease.OutElastic)
        .SetId(this);

        other.Pop();
    }
Esempio n. 3
0
    private IEnumerator SpawnRoutine()
    {
        while (enabled)
        {
            while (_microphone.Value < _spawnThreshold)
            {
                yield return(null);
            }

            _bubbleInProgress = SpawnBubble();

            {
                var size      = 0.01f;
                var startTime = Time.realtimeSinceStartup;

                while (_microphone.Value > _spawnThreshold &&
                       size < _maxSize &&
                       Time.realtimeSinceStartup - _maxTime < startTime)
                {
                    size += _microphone.Value * _growSpeed;

                    _bubbleInProgress.SetSize(size);
                    yield return(null);
                }
            }

            _bubbleInProgress.Release((_bubbleSpawnHolder.TransformDirection(_releaseDir).normalized) * _releaseForce);
            _bubbleInProgress = null;

            SpawnedBubbles++;

            {
                var startTime = Time.realtimeSinceStartup;
                while (_microphone.Value > _spawnThreshold && Time.realtimeSinceStartup - _intervalTime < startTime)
                {
                    yield return(null);
                }
            }
        }
    }