Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question How to focus enemy chasing me?

Discussion in 'Scripting' started by ch66666, Jul 31, 2020.

  1. ch66666

    ch66666

    Joined:
    Jul 3, 2020
    Posts:
    7
    first of all, im a beginner so im sorry if my code is a huge mess. id like to know why my enemy is going its path even tho im making him chase me. so pretty much i want him to chase me and ignore his path, and if hes not chasing me to go again on his path. how would i do that? and also any tips are highly appreciated.

    upload_2020-7-31_21-15-27.png
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,735
    Since you previously set the destination of the NavMeshAgent, it doesn't matter what you do with your
    canWander
    variable, it will continue to navigate to that original destination. The NavMeshAgent can't see that variable and doesn't know anything about it. You need to set a different destination (the player's position?) for the NavMeshAgent to get the monster to chase the player.
     
    ch66666 likes this.
  3. ch66666

    ch66666

    Joined:
    Jul 3, 2020
    Posts:
    7
    youre a genius, thank you
     
  4. ch66666

    ch66666

    Joined:
    Jul 3, 2020
    Posts:
    7
    sadly it still goes on its own path and ignores me completely. any other suggestions?
     
  5. Yanne065

    Yanne065

    Joined:
    Feb 24, 2018
    Posts:
    175
    Post the new code by using code tag