public void Move() { if (!CanMove) { return; } // _parallelMovingCheck.Tick(); if (_movementPackage.Destination.DestinationType == DestinationType.Intersection && !_movementPackage.Finished) { if (InRedirectRange()) { _movementPackage.Destination.TargetLocation = _movementPackage.IntersectionAnalysis.IntersectingUnit .AngleDefinition.IntersectionPoint; HandleIntersectionTimeSlow(); var successfulRedirect = RedirectEvaluator.ValidRedirect( _movementPackage.IntersectionAnalysis.IntersectingUnit.Transform.position, _movementPackage.Destination.TargetLocation, 0.85f); if (PassedRedirectRange()) { NewMovementPackageRequested?.Invoke(_movementPackage, SetMovementPackage, successfulRedirect); Time.timeScale = 1f; _currentMoveSpeed = _defaultMoveSpeed * 1.5f; } } } if (InRequestRange() && _movementPackage.Destination.DestinationType == DestinationType.ClosestPointToEnemy && !_movementPackage.Finished) { if (!_requested) { _requested = true; NewMovementPackageRequested?.Invoke(_movementPackage, SetMovementPackage, false); } } if (_movementPackage.Finished && !_isInDanger) { _currentMoveSpeed = _defaultMoveSpeed * 2f; } if (Arrived(_movementPackage.Destination.TargetLocation)) { OnArrival?.Invoke(); Reset(); return; } IsMoving = true; _transform.position = Vector2.MoveTowards(_transform.position, _movementPackage.Destination.TargetLocation, _currentMoveSpeed * Time.deltaTime); }
private void HandleIntersection() { if (_currentPlan.HeadingForIntersection && InRedirectRange() && !_currentPlan.HeadingForObstacle) { _mover.GetComponent <Collider2D>().enabled = false; _currentPlan.UpdateTargetLocationWhileMovingToIntersect(_currentPlan.TargetUnit.AngleDefinition.IntersectionPoint); DoTimeSlow(); var successfulRedirect = RedirectEvaluator.ValidRedirect( _currentPlan.TargetUnit.Transform.position, _currentPlan.TargetLocation, 0.85f); if (PassedRedirectRange()) { _mover.GetComponent <Collider2D>().enabled = false; RequestedNewPackage?.Invoke(); MovementPlanRequested?.Invoke(_currentPlan, SetCurrentPlan, successfulRedirect, false); Time.timeScale = 1f; _currentMoveSpeed = _defaultMoveSpeed * 1.5f; } } }