Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.34 KB | None | 0 0
  1. IEnumerator UpdatePath()
  2. {
  3. float refreshRate = .25f;
  4.  
  5. while (hasTarget)
  6. {
  7. if (lastKnownPosition.y > 0)
  8. {
  9. lastKnownPosition.y = 0f;
  10. }
  11.  
  12. if (!dead && pathfinder.enabled)
  13. {
  14. // cas du chasing -- lancé si playerInSight
  15. if (currentState == State.Chasing)
  16. {
  17. Vector3 dirToTarget = (target.position - transform.position).normalized;
  18. Vector3 targetPosition = target.position - dirToTarget * (myCollisionRadius + targetCollisionRadius + attackDistanceThreshold/2);
  19. targetPosition.y = 0;
  20.  
  21. pathfinder.SetDestination(targetPosition);
  22.  
  23. }
  24.  
  25. // Cas du searching -- lancé si searchingPlayer
  26. else if (currentState == State.Searching)
  27. {
  28. if ((map.GetTileFromPosition(transform.position) == map.GetTileFromPosition(lastKnownPosition)) && !hasReachedDestination)
  29. {
  30. hasReachedDestination = true;
  31. }
  32.  
  33. if (hasReachedDestination && !destinationCheck)
  34. {
  35. destinationCheck = true;
  36. // On vérifie si le joueur est posté sur un obstacle
  37. StartCoroutine(SearchDestinationCheck());
  38. }
  39. else
  40. {
  41. //Debug.Log("searching last position : " + map.GetTileFromPosition(lastKnownPosition).GetComponent<Renderer>().material.color);
  42. pathfinder.SetDestination (lastKnownPosition);
  43. }
  44. }
  45.  
  46. // cas du patroling
  47. else if (currentState == State.Patroling)
  48. //Debug.Log("patroling...");
  49. {
  50. if (hasReachedDestination && !destinationCheck)
  51. {
  52. destinationCheck = true;
  53. StartCoroutine(SearchDestinationCheck());
  54. }
  55.  
  56. if (pathfinder.enabled)
  57. {
  58. pathfinder.SetDestination(destinationTile.position); //rajouté pour corriger un message d'erreur qui revenait
  59. }
  60.  
  61. //Arrivée à la destination
  62. if ((map.GetTileFromPosition(transform.position) == destinationTile))
  63. {
  64. hasReachedDestination = true;
  65. }
  66. }
  67. }
  68. yield return new WaitForSeconds(refreshRate);
  69. }
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement