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. Dismiss Notice

Basic Enemy AI Script (Missing Field Exeptions)

Discussion in 'Scripting' started by Dryzon_3S, Jun 14, 2014.

  1. Dryzon_3S

    Dryzon_3S

    Joined:
    Jun 13, 2014
    Posts:
    3
    Hey, I just made this java script for my enemy's AI:
    Code (JavaScript):
    1. var Distance;
    2. var Target : Transform;
    3. var lookAtDistance = 25.0;
    4. var attackRange = 15.0;
    5. var moveSpeed = 5.0;
    6. var Damping = 6.0;
    7.  
    8. function Update ()
    9. {
    10.     Distance = Vector3.Distance(Target.position, transform.position.position);
    11.    
    12.     if (Distance < lookAtDistance)
    13.     {
    14.         looAt();
    15.     }  
    16.    
    17.     if (Distance < attackRange)
    18.     {
    19.         attack ();
    20.     }
    21. }
    22.  
    23. function looAt ()
    24. {
    25.     var rotation = Quaternion.LookRotation(Target.position - transform.position);
    26.     transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
    27. }      
    28.  
    29. function attack ()
    30. {
    31.     transform.Translate(Vector3.forward * moveSpeed * Time.deltaTime);
    32. }
    But Unity gives me this error displayed in the attached picture file
    Any help greatly appreciated!
     

    Attached Files:

  2. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    transform.position.position?
     
  3. Dryzon_3S

    Dryzon_3S

    Joined:
    Jun 13, 2014
    Posts:
    3
    Yes that was the problem, really noob of me.
    Though I have another problem, the model I have written this script for flies towards the player a little above the ground? What can I do to make him walk towards the player?
     
  4. jister

    jister

    Joined:
    Oct 9, 2009
    Posts:
    1,749
    give it a rigidbody with gravity?