private IEnumerator AddCrossSection(DartChainV2 currentFirstChain)
    {
        float distance = Vector3.Distance(currentFirstChain.transform.position, _dartSpawnPoint.transform.position);

        /*while (distance <= _crossSectionLength)
         * {
         *  distance = Vector3.Distance(currentFirstChain.transform.position, _dartSpawnPoint.transform.position);
         *  yield return null;
         * }*/
        var crossSectionsNeeded = distance / _crossSectionLength;

        lastDartChainAdded = currentFirstChain;
        int numberOfIterations = Mathf.RoundToInt(crossSectionsNeeded);

        for (int i = 0; i < numberOfIterations; i++)
        {
            lastDartChainAdded = InstantiateChain(lastDartChainAdded);
        }

        yield return(null);

        _addCrossSection = AddCrossSection(lastDartChainAdded);
        _currentCount++;
        if (_currentCount < _crossSectionsLimit)
        {
            StartCoroutine(_addCrossSection);
        }
        else
        {
            lastDartChainAdded.transform.parent          = _dartSpawnPoint.transform;
            lastDartChainAdded.MainRigidbody.isKinematic = true;
            _moveLastChainToRefPoint = MoveLastChainToRefPoint(lastDartChainAdded);
            StartCoroutine(_moveLastChainToRefPoint);
        }
    }
 private IEnumerator MoveLastChainToRefPoint(DartChainV2 lastDartChainAdded)
 {
     while (true)
     {
         lastDartChainAdded.transform.position = _dartSpawnPoint.transform.position;
         yield return(null);
     }
 }
Beispiel #3
0
 private void CascadeToNeighbour(GameObject measureDistanceTo, DartChainV2 targettocascade)
 {
     if (!_isStaticChain)
     {
         var distancetochain = Vector3.Distance(measureDistanceTo.transform.position, transform.position);
         if (distancetochain >= CurrentGun.Settings.HoseLength)
         {
             var direction = measureDistanceTo.transform.position - transform.position;
             MainRigidbody.AddForce(direction.normalized * _maxForce * distancetochain);
             targettocascade.CascadeForce(this, _maxForce * _mitigationFactor * distancetochain);
         }
     }
 }
    private DartChainV2 InstantiateChain(DartChainV2 toAttachTo, Dart dart = null)
    {
        dart = dart ?? toAttachTo.CurrentDart;
        var brandNewCrossSection =
            (DartChainV2)
            Instantiate(_dartChainPrefab, _dartSpawnPoint.transform.position, _dartSpawnPoint.transform.rotation);

        brandNewCrossSection.CurrentGun       = this;
        brandNewCrossSection.CurrentDart      = dart;
        brandNewCrossSection.NextChain        = toAttachTo;
        brandNewCrossSection.transform.parent = dart.transform;

        dart.ListenToCrossSection(brandNewCrossSection);
        return(brandNewCrossSection);
    }
Beispiel #5
0
 private void CascadeForce(DartChainV2 source, float forcetoAdd)
 {
     if (!_isStaticChain)
     {
         var direction = source.transform.position - transform.position;
         MainRigidbody.AddForce(direction.normalized * forcetoAdd);
         if (source == PreviousChain)
         {
             NextChain.CascadeForce(this, forcetoAdd * _mitigationFactor);
         }
         else if (source == NextChain)
         {
             PreviousChain.CascadeForce(this, forcetoAdd * _mitigationFactor);
         }
     }
 }
Beispiel #6
0
 private void CascadeToNeighbour(GameObject measureDistanceTo, DartChainV2 targettocascade)
 {
     if (!_isStaticChain)
     {
         var distancetochain = Vector3.Distance(measureDistanceTo.transform.position, transform.position);
         if (distancetochain >= CurrentGun.Settings.HoseLength)
         {
             var direction = measureDistanceTo.transform.position - transform.position;
             MainRigidbody.AddForce(direction.normalized*_maxForce*distancetochain);
             targettocascade.CascadeForce(this, _maxForce*_mitigationFactor*distancetochain);
         }
     }
 }
Beispiel #7
0
 private void CascadeForce(DartChainV2 source, float forcetoAdd)
 {
     if (!_isStaticChain)
     {
         var direction = source.transform.position - transform.position;
         MainRigidbody.AddForce(direction.normalized*forcetoAdd);
         if (source == PreviousChain)
         {
             NextChain.CascadeForce(this, forcetoAdd*_mitigationFactor);
         }
         else if (source == NextChain)
         {
             PreviousChain.CascadeForce(this, forcetoAdd*_mitigationFactor);
         }
     }
 }
Beispiel #8
0
 public void ListenToCrossSection(DartChainV2 brandNewCrossSection)
 {
     brandNewCrossSection.HitFloor          += HitFloor;
     brandNewCrossSection.BrokenOnTolerance += BrokenOnTolerance;
 }
 private IEnumerator MoveLastChainToRefPoint(DartChainV2 lastDartChainAdded)
 {
     while (true)
     {
         lastDartChainAdded.transform.position = _dartSpawnPoint.transform.position;
         yield return null;
     }
 }
Beispiel #10
0
    private DartChainV2 InstantiateChain(DartChainV2 toAttachTo, Dart dart = null)
    {
        dart = dart ?? toAttachTo.CurrentDart;
        var brandNewCrossSection =
            (DartChainV2)
                Instantiate(_dartChainPrefab, _dartSpawnPoint.transform.position, _dartSpawnPoint.transform.rotation);
        brandNewCrossSection.CurrentGun = this;
        brandNewCrossSection.CurrentDart = dart;
        brandNewCrossSection.NextChain = toAttachTo;
        brandNewCrossSection.transform.parent = dart.transform;

        dart.ListenToCrossSection(brandNewCrossSection);
        return brandNewCrossSection;
    }
Beispiel #11
0
    private IEnumerator AddCrossSection(DartChainV2 currentFirstChain)
    {
        float distance = Vector3.Distance(currentFirstChain.transform.position, _dartSpawnPoint.transform.position);
        /*while (distance <= _crossSectionLength)
        {
            distance = Vector3.Distance(currentFirstChain.transform.position, _dartSpawnPoint.transform.position);
            yield return null;
        }*/
        var crossSectionsNeeded = distance/_crossSectionLength;
        lastDartChainAdded = currentFirstChain;
        int numberOfIterations = Mathf.RoundToInt(crossSectionsNeeded);
        for (int i = 0; i < numberOfIterations; i++)
        {
            lastDartChainAdded = InstantiateChain(lastDartChainAdded);
        }

        yield return null;
        _addCrossSection = AddCrossSection(lastDartChainAdded);
        _currentCount ++;
        if (_currentCount < _crossSectionsLimit) StartCoroutine(_addCrossSection);
        else
        {
            lastDartChainAdded.transform.parent = _dartSpawnPoint.transform;
            lastDartChainAdded.MainRigidbody.isKinematic = true;
            _moveLastChainToRefPoint = MoveLastChainToRefPoint(lastDartChainAdded);
            StartCoroutine(_moveLastChainToRefPoint);
        }
    }
Beispiel #12
0
 public void ListenToCrossSection(DartChainV2 brandNewCrossSection)
 {
     brandNewCrossSection.HitFloor += HitFloor;
     brandNewCrossSection.BrokenOnTolerance += BrokenOnTolerance;
 }