Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by FPSworrior · Dec 11, 2013 at 11:34 PM · errorailookat

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

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer Wiki

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

Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Paparakas · Dec 12, 2013 at 12:56 AM 2
Share

$$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);

avatar image Ryuuzoji · Dec 12, 2013 at 08:29 AM 0
Share

Right. I tend to forget that as I work in Unity's "Javascript"

avatar image FPSworrior · Dec 12, 2013 at 03:40 PM 0
Share

I ended up figuring out the problem before you guys posted the answers, but thank you for the help anyway.

avatar image
1

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.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
1

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);
        }
Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image flaviusxvii · Dec 11, 2013 at 11:48 PM 0
Share

Nvm.. never new about that other version.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

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


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges