- Home /
 
What's wrong with my AI script.
I have my script here but I don't know how to fix the error. /Scripts/AI.cs(37,35): error CS1501: No overload for method LookAt' takes 3' arguments
 using UnityEngine;
 using System.Collections;
 
 public class AI : MonoBehaviour {
     public int health = 100;
     public Transform target;
     public bool foundTarget = false;
     public int movespeed;
     public int rotateSpeed;
     private bool takeDamage = false;
     public Transform myTransform;
 
 
 
     // Use this for initialization
     void Start () {
         takeDamage = false;
         myTransform = transform;
         target = GameObject.FindWithTag("Player").transform;
     
     }
     
     // Update is called once per frame
     void Update () {
 
         if(takeDamage == true)
         {
             health -= 10;
         }
         if(health == 0)
         {
             gameObject.SetActive(false);
             takeDamage = false;
         }
         if(foundTarget && health > 0)
         {
             transform.LookAt(target.position.x, transform.position.y, target.position.z);
             myTransform.Translate(Vector3.forward * movespeed * Time.deltaTime);
         }
 
 
     
     }
 
     void OnTriggerEnter(Collider other)
     {
         if(other.gameObject.tag == "Bullet")
         {
             takeDamage = true;
         }
 
         if(other.gameObject.tag == "Player")
         {
             foundTarget = true;
         }
     }
 
     void OnTriggerStay(Collider other)
     {
         if(other.gameObject.tag == "Bullet")
         {
             takeDamage = true;
         }
     }
 
     void OnTriggerExit(Collider other)
     {
         if(other.gameObject.tag == "Bullet")
         {
             takeDamage = false;
         }
     }
 }
 
               Assets/Jason's Stuff/Scripts/AI.cs(37,35): error CS1501: No overload for method LookAt' takes 3' arguments 
Answer by Ryuuzoji · Dec 12, 2013 at 12:28 AM
Hey.
Your problem comes up because there is no method for LookAt that takes 3 arguments, which you are feeding it in the form of an x, y and z, coordinate. You need these to be given as one argument, i.e. a vector 3.
You can solve this in 2 ways I can think of. If you are trying to make it look at a GameObject (a target), save that target in a GameObject variable and simply write
 transform.LookAt(target);
 
               You might even be able to solve it with just this
 transform.LookAt(target.gameObject);
 
               Otherwise, you can just go ahead and write, which I think should solve it too. ´
 transform.LookAt(vector3(target.position.x, target.position.y, target.position.z);
 
               Good luck and have fun making games
$$anonymous$$inor addition: Since he's using C# the third option would have to be transform.LookAt(new Vector3(target.position.x, target.position.y, target.position.z);
Right. I tend to forget that as I work in Unity's "Javascript"
I ended up figuring out the problem before you guys posted the answers, but thank you for the help anyway.
Answer by flaviusxvii · Dec 11, 2013 at 11:44 PM
http://docs.unity3d.com/Documentation/ScriptReference/Transform.LookAt.html
LookAt takes a whole Vector3.. not the pieces of one.
Answer by EX_Darius · Dec 11, 2013 at 11:47 PM
You are not using the "LookAt" reference as intended, seeing it only takes 2 arguments. http://docs.unity3d.com/Documentation/ScriptReference/Transform.LookAt.html
So replace "transform.LookAt(target.position.x, transform.position.y, target.position.z);"
With:
"transform.LookAt(target);"
If you absolutely need to have the y of the current gameobject, you can simply do this:
 if(foundTarget && health > 0)
        {
 target.position.y = transform.position.y; 
 transform.LookAt(target);
 myTransform.Translate(Vector3.forward * movespeed * Time.deltaTime);
        }
 
              Your answer
 
             Follow this Question
Related Questions
Why am I getting this error? 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
Damage the Player 1 Answer
; expected. Insert a semicolon at the end. 1 Answer
Script error help! 1 Answer