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 Quags · Aug 29, 2013 at 11:40 PM · c#aifollow

still have some problems with c# AI

posted before and got some help but still have a couple of problems. just trying to get the AI follow my player. these are the errors im getting:

Assets/AIfollow.cs(25,51): error CS1501: No overload for method Slerp' takes 1' arguments

Assets/AIfollow.cs(26,36): error CS0117: UnityEngine.Quaternion' does not contain a definition for rotation'

here is my script:

 using UnityEngine;
 using System.Collections;
 
 public class AIfollow : MonoBehaviour {
 
     private Transform myTransform; //current transform data of this enemy
     private Transform target; //the enemy's target
     private int moveSpeed = 3; //move speed
     private int rotationSpeed = 3; //speed of turning
  
         
         void Awake()
         {
             myTransform = transform; //cache transform data for easy access/preformance
         }
  
         void Start()
         {
                 target = GameObject.FindWithTag("AIattack").transform; //target the player
          }
  
         void Update () {
         
         //rotate to look at the player
             myTransform.rotation = Quaternion.Slerp(myTransform.rotation);
              Quaternion.rotation((target.position - myTransform.position), (rotationSpeed*Time.deltaTime));
  
         //move towards the player
             myTransform.position += myTransform.forward * moveSpeed * Time.deltaTime;
  }
 }
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

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by getyour411 · Aug 29, 2013 at 11:44 PM

I think this

  myTransform.rotation = Quaternion.Slerp(myTransform.rotation);
 Quaternion.rotation((target.position - myTransform.position), (rotationSpeed*Time.deltaTime))



should be this

 myTransform.rotation = Quaternion.Slerp(myTransform.rotation,
 Quaternion.LookRotation((target.position - myTransform.position), (rotationSpeed*Time.deltaTime));
Comment
Add comment · Show 4 · 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 Quags · Aug 30, 2013 at 12:14 AM 0
Share

ok so i fixed it to: myTransform.rotation = Quaternion.Slerp(myTransform.rotation, Quaternion.LookRotation(target.position - myTransform.position), rotationSpeed*Time.deltaTime); it lets me hit play and move around but the AI just sits there and i get these errors:

UnityException: Tag: AIattack is not defined! UnityEngine.GameObject.FindWithTag (System.String tag) (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/UnityEngineGameObject.cs:321) AIfollow.Start () (at Assets/AIfollow.cs:19)

NullReferenceException UnityEngine.Transform.get_position () (at C:/BuildAgent/work/7535de4ca26c26ac/Runtime/ExportGenerated/Editor/UnityEngineTransform.cs:26) AIfollow.Update () (at Assets/AIfollow.cs:25)

avatar image perchik · Aug 30, 2013 at 12:23 AM 0
Share

Your new Error is telling you that it's not finding anything with that Tag. The null reference exception is because you never check to see if you actually found an object.

Are you sure your object actually has that tag?

avatar image Quags · Aug 30, 2013 at 04:39 AM 0
Share

yeah im positive that it has the same name as the object i put it on

avatar image getyour411 · Aug 31, 2013 at 03:15 AM 0
Share

You have this

  target = GameObject.FindWithTag("AIattack").transform; //target the player

which seems like a roundabout way of getting the player, change "AIattack" to "Player"

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

18 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

Related Questions

Advice on my Ship AI... 4 Answers

Distribute terrain in zones 3 Answers

Multiple Cars not working 1 Answer

How can I more optimize My AI Script 0 Answers

Help with Enemy AI 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