private void HandlePotentialFinished() { if (InRequestRange() && !_currentPlan.Finished && !_currentPlan.HeadingForIntersection && !_currentPlan.HeadingForObstacle) { _mover.GetComponent <Collider2D>().enabled = false; _currentMoveSpeed = _defaultMoveSpeed; RequestedNewPackage?.Invoke(); MovementPlanRequested?.Invoke(_currentPlan, SetCurrentPlan, false, false); } }
public void Tick() { if (!IsMoving) { _mover.GetComponent <Collider2D>().enabled = true; return; } if (_currentPlan.TargetUnit != null && Vector2.Distance(_currentPlan.TargetUnit.Transform.position, _mover.position) < 3f) { _mover.GetComponent <Collider2D>().enabled = false; } if (_currentPlan.IsFirst) { OnFirstMove?.Invoke(); } if (InRequestRange() && _currentPlan.HeadingForObstacle) { _mover.GetComponent <Collider2D>().enabled = false; MovementPlanRequested?.Invoke(_currentPlan, SetCurrentPlan, false, _currentPlan.HeadingForObstacle); _currentMoveSpeed = _defaultMoveSpeed; } HandleIntersection(); HandlePotentialFinished(); IncreaseSpeedOnFinalMovement(); if (Arrived(_currentPlan.TargetLocation)) { Reset(); return; } _mover.position = Vector2.MoveTowards(_mover.position, _currentPlan.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; } } }