IEnumerator IEDestination() { m_state = EAgentState.Move; Vector3 currPos = m_path.Pop(); int count = 0; while (m_path.Count > 1) { yield return(null); if (transform.position == currPos) { currPos = m_path.Pop(); ++count; } Vector3 prev = transform.position; Vector3 next = Vector3.MoveTowards(prev, currPos, m_speed * Time.deltaTime); m_velocity = next - prev; transform.position = next; } m_currCoroutine = null; m_velocity = Vector2.zero; m_state = EAgentState.Standby; }
public void SetDestination(Vector3 position) { if (m_currCoroutine != null) { StopCoroutine(m_currCoroutine); } m_state = EAgentState.Wait; AStarMng.Instance.RequestPathfinding(this, transform.position, position); }
private void Update() { UpdateTarget(); // If no target go back to idle if (!_targetFinder.Target) { _currentAgentState = EAgentState.Idle; } switch (_currentAgentState) { case EAgentState.Idle: if (_targetFinder.Target) { _currentAgentState = EAgentState.Move; } break; case EAgentState.Move: if (_attackComponent.IsTargetInRange(_targetFinder.Target)) { _currentAgentState = EAgentState.Attack; _movementComponent.StopNavigation(); } else { _movementComponent.OnUpdate(); } break; case EAgentState.Attack: if (_attackComponent.IsTargetInRange(_targetFinder.Target)) { _attackComponent.OnUpdate(); } else { _currentAgentState = EAgentState.Move; } break; } }
public void Stop() { m_velocity = Vector2.zero; m_state = EAgentState.Standby; }
public void Reset() { _currentAgentState = EAgentState.Idle; }