Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- IEnumerator UpdatePath()
- {
- float refreshRate = .25f;
- while (hasTarget)
- {
- if (lastKnownPosition.y > 0)
- {
- lastKnownPosition.y = 0f;
- }
- if (!dead && pathfinder.enabled)
- {
- // cas du chasing -- lancé si playerInSight
- if (currentState == State.Chasing)
- {
- Vector3 dirToTarget = (target.position - transform.position).normalized;
- Vector3 targetPosition = target.position - dirToTarget * (myCollisionRadius + targetCollisionRadius + attackDistanceThreshold/2);
- targetPosition.y = 0;
- pathfinder.SetDestination(targetPosition);
- }
- // Cas du searching -- lancé si searchingPlayer
- else if (currentState == State.Searching)
- {
- if ((map.GetTileFromPosition(transform.position) == map.GetTileFromPosition(lastKnownPosition)) && !hasReachedDestination)
- {
- hasReachedDestination = true;
- }
- if (hasReachedDestination && !destinationCheck)
- {
- destinationCheck = true;
- // On vérifie si le joueur est posté sur un obstacle
- StartCoroutine(SearchDestinationCheck());
- }
- else
- {
- //Debug.Log("searching last position : " + map.GetTileFromPosition(lastKnownPosition).GetComponent<Renderer>().material.color);
- pathfinder.SetDestination (lastKnownPosition);
- }
- }
- // cas du patroling
- else if (currentState == State.Patroling)
- //Debug.Log("patroling...");
- {
- if (hasReachedDestination && !destinationCheck)
- {
- destinationCheck = true;
- StartCoroutine(SearchDestinationCheck());
- }
- if (pathfinder.enabled)
- {
- pathfinder.SetDestination(destinationTile.position); //rajouté pour corriger un message d'erreur qui revenait
- }
- //Arrivée à la destination
- if ((map.GetTileFromPosition(transform.position) == destinationTile))
- {
- hasReachedDestination = true;
- }
- }
- }
- yield return new WaitForSeconds(refreshRate);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement