// Update is called once per frame void Update() { if (stopped) { animator.Play("idle"); return; } if (!isPursuing) { if (!playerTracker.PlayerDetected) { // Patrolling State = EnemyState.State.Patrol; if (Mathf.Abs(Vector3.Distance(this.transform.position, route.GetCurrentRoutePoint())) > 1f) { agent.destination = route.GetCurrentRoutePoint(); animator.Play("run"); // Debug.Log("didnt reach point"); } else { route.NextRoutePoint(); //Debug.Log("reach point"); } } else { // Begin pursuit isPursuing = true; } } else // Pursuit! { if (playerTracker.PlayerDetected) { if (currentBehaviour != null) { // Continue Pursuit case StopCoroutine(currentBehaviour); currentBehaviour = null; } State = EnemyState.State.Pursuit; agent.destination = playerTracker.GetPlayerPosition(); animator.Play("charge"); } else { if (currentBehaviour == null) { // Begin close search agent.destination = this.transform.position; State = EnemyState.State.CloseSearch; currentBehaviour = StartCoroutine(CloseSearchPlayerBehaviour()); animator.Play("idle"); } } } }
void ChangeStateAttributes(EnemyState.State nextState) { EnemyState data; statesDict.TryGetValue(nextState, out data); moveSpeed = data.moveSpeed; angularSpeed = data.angularSpeed; perception.ChangeConeScale(data.visibilityConeScale); }
// Start is called before the first frame update void Start() { perception = transform.Find("VisionCone").GetComponent <EnemyPerceptionController>(); statesDict = EnemyState.GetStatesDictionary(); currentState = EnemyState.State.Patrol; route.SetupRoute(); SetupNavMeshAgent(); playerTracker = this.GetComponent <PlayerTracker>(); player = GameObject.FindObjectOfType <PlayerController>(); virtualCamera = gameObject.GetComponentInChildren <CinemachineVirtualCamera>(); animator = gameObject.GetComponent <Animator>(); animator.Play("idle"); }