Search Unity

Enemy tracking script problem

Discussion in 'Getting Started' started by phantomunboxing, Jan 6, 2016.

  1. phantomunboxing

    phantomunboxing

    Joined:
    Nov 10, 2015
    Posts:
    43
    Video

    Download http://www.mediafire.com/view/e81xr2tqw5qnag0/EnemySpawner.js

    var enabled = false;
    var triggered = false;

    var player : Transform;
    var zombie : Transform;

    var MoveSpeed = 4;
    var MinDist = 5;
    var MaxDist = 10;



    function EnemyNewPosition()
    {
    Zombie.transform.position.x = player.transform.position.x - 50;
    Zombie.transform.position.y = player.transform.position.xy - 150;
    }

    function chase()
    {
    Zombie.LookAt (Player);

    if(Vector3.Distance(Zombie.position,PlayerPrefs.position ) >= MinDist {
    zombie.position += zombie.foward * MoveSpeed*Time.deltatime;

    if(Vector3.Distance(Zombie.position,PlayerPrefs.position ) <= MaxDist
    {
    Destroy(Zombie);
    }
    }
    }

    function Start ()
    {
    triggered = false;
    }

    function OnTriggerEnter()
    {
    triggered = true;
    EnemyNewPosition();
    }

    Function Update ()
    {
    if (triggered == true;
    {
    DoTrigger();
    }
    }

    function DoTrigger()
    {
    Chase();
    }
     
  2. JoeStrout

    JoeStrout

    Joined:
    Jan 14, 2011
    Posts:
    9,859
    Apart from not knowing how to use CODE tags... what is the problem?
     
  3. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    814
    I don't know if this is the problem you are asking about (as joes points out, you didn't actually tell us what the error is) but at a glance I notice you mixed up the capitalization on chase()/Chase()
     
  4. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,129
    There are two major problems with your script.

    Code (csharp):
    1. function DoTrigger()
    2. {
    3.     Chase();
    4. }
    First, as was mentioned in the previous post UnityScript is case sensitive. The function above is trying to call another function named "Chase", but your function definition below is named "chase". Since UnityScript is case sensitive it is treating those as two different functions.

    Code (csharp):
    1. function chase()
    2. {
    3.     Zombie.LookAt (Player);
    4.  
    5.         if(Vector3.Distance(Zombie.position,PlayerPrefs.position ) >= MinDist {
    6.         zombie.position += zombie.foward * MoveSpeed*Time.deltatime;
    7.  
    8.         if(Vector3.Distance(Zombie.position,PlayerPrefs.position ) <= MaxDist
    9.         {
    10.         Destroy(Zombie);
    11.         }
    12.     }
    13. }
    Additionally you're not using enough closing parentheses. Both the above and below functions have more opening parentheses than closing parentheses. The number of opening and closing parentheses must be the same.

    Code (csharp):
    1. Function Update ()
    2. {
    3.     if (triggered == true;
    4.     {
    5.         DoTrigger();
    6.     }
    7. }
     
    Last edited: Jan 7, 2016
    JoeStrout likes this.
  5. phantomunboxing

    phantomunboxing

    Joined:
    Nov 10, 2015
    Posts:
    43
    I am still getting error (23,87) expecting ) found {
    (27,17) expecting ) found {
    (30,9) expecting EOF found }
     
  6. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    814
    That error tells you what you need to do: go to line 23 and add a missing ). You're missing a ) at the end of the 'if' statement.
     
  7. phantomunboxing

    phantomunboxing

    Joined:
    Nov 10, 2015
    Posts:
    43
    var enabled = false;
    var triggered = false;

    var player : Transform;
    var zombie : Transform;

    var MoveSpeed = 4;
    var MinDist = 5;
    var MaxDist = 10;



    function EnemyNewPosition()
    {
    Zombie.transform.position.x = player.transform.position.x - 50;
    Zombie.transform.position.y = player.transform.position.xy - 150;
    }

    function Chase()
    {
    Zombie.LookAt (Player);

    if(Vector3.Distance(Zombie.position,Player.position ) >= MinDist {
    Zombie.position += Zombie.foward * MoveSpeed*Time.deltatime;

    if(Vector3.Distance(Zombie.position,Player.position ) <= MaxDist
    {
    Destroy(Zombie);
    }
    }
    }

    function Start ()
    {
    triggered = false;
    }

    function OnTriggerEnter()
    {
    triggered = true;
    EnemyNewPosition();
    }

    Function Update ()
    {
    if (triggered == true;
    {
    DoTrigger();
    }
    }

    function DoTrigger()
    {
    Chase();
    }

    Still getting the same errors D:
     
  8. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,129
    Of course you are. You haven't changed anything. We told you what was wrong. What's stopping you from fixing it? This may come across as a bit blunt and/or mean, but if you can't handle fixing the problems after we explained how then you may as well stop now. These are very simple problems. It only gets harder going forward.
     
    Schneider21 and jhocking like this.
  9. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    814
    You're still not using code tags btw, even after joes specifically pointed that out. If you used code tags then we could see line numbers; right now we have to count, which is annoying.
     
    Ryiah likes this.
  10. phantomunboxing

    phantomunboxing

    Joined:
    Nov 10, 2015
    Posts:
    43
    I am new to coding as stated by putting it in the beginner section. Could you talk about these as text not in code langauge to make it easier to understand....
     
  11. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,129
  12. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    814
  13. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    What is
    Player.transform.position.xy ?
     
  14. tedthebug

    tedthebug

    Joined:
    May 6, 2015
    Posts:
    2,570
    Also, if you are new to coding perhaps you should be doing the easier tutorials instead of the advanced enemy AI one?
     
    Ryiah and jhocking like this.
  15. jhocking

    jhocking

    Joined:
    Nov 21, 2009
    Posts:
    814
    oh yeah that's true, I didn't even notice that. These are really basic programming questions you are asking, nowhere near where you should be to tackle advanced AI.
     
  16. Ryiah

    Ryiah

    Joined:
    Oct 11, 2012
    Posts:
    21,129
    Just a typo if I'm not mistaken. I doubt he's trying to use GLSL's swizzling. :p