protected virtual void ChaseTarget() { m_PathToTarget.Clear(); if (m_CurrentTarget == null) { GetTargetInRange(); } if (m_CurrentTarget == null) { return; } // Attack if (TryToAttackWhenPossible) { var targetPosition = m_CurrentTarget.m_GridPosition; var gridObjectAtPosition = GridManager.Instance.GetGridObjectAtPosition(targetPosition); if (gridObjectAtPosition != null && m_Attack != null) { var healthComponents = m_Attack.GetVictimsFromTriggerAtPosition(targetPosition); if (healthComponents != null && healthComponents.Count > 0) { var attkResult = m_Attack.TryAttack(targetPosition); if (attkResult == AttackResult.Success) { return; } } } } // Movement if (_gridObject.m_GridPosition.GridDistance(m_CurrentTarget.m_GridPosition) > 1) { // Calculate a path and try moving towards the target m_PathToTarget = AStar.Search(_gridObject.m_CurrentGridTile, m_CurrentTarget.m_CurrentGridTile); if (m_PathToTarget != null && m_PathToTarget.Count > 0 && m_PathToTarget.Contains(m_CurrentTarget.m_CurrentGridTile)) { _gridMovement.TryMoveTo(m_PathToTarget[0]); } } else // Rotation { var targetDirection = m_CurrentTarget.m_GridPosition; var rotated = _gridMovement.TryRotateTo(targetDirection); } }