Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 dudedude123 · Dec 04, 2017 at 12:41 AM · scripting problemai

AI targeting error

I'm working on an AI class and I almost have it finished. I keep getting errors on this script

          private Transform[] target;
 
     private float Distance;
     private float lookAtDistance = 25.0f;
     private float chaseRange = 15.0f;
     private float attackRange = 1.5f;
     private float moveSpeed = 5.0f;
     private float Damping = 6.0f;
     private float attackRepeatTime = 1;
 
  void lookAt()
         {
     
             float rotation = Quaternion.LookRotation(target.position - transform.position);
             transform.rotation = Quaternion.Slerp(transform.rotation, rotation, Time.deltaTime * Damping);
         }
 

Severity Code Description Project File Line Suppression State Error CS1061 'Transform[]' does not contain a definition for 'position' and no extension method 'position' accepting a first argument of type 'Transform[]' could be found (are you missing a using directive or an assembly reference?) Beatdown C:\Users\garre\OneDrive\Documents\Projects\Games\Beatdown\Assets\BoxerAI.cs 92 Active Error CS1503 Argument 2: cannot convert from 'float' to 'UnityEngine.Quaternion' Beatdown C:\Users\garre\OneDrive\Documents\Projects\Games\Beatdown\Assets\BoxerAI.cs 93 Active

How can I fix this?

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

2 Replies

· Add your reply
  • Sort: 
avatar image
0

Answer by UnityVeris · Dec 04, 2017 at 05:48 AM

Post the whole script, it seems you're missing assembly references.

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
0

Answer by JaredHD · Dec 04, 2017 at 05:50 AM

Error 1

Hmm ok. Error 1, You've created an array of transforms, private Transform[] target and than you access the array incorrectly by doing, target.position. An array is a holder, so you can't just get the position out of the array. You need to tell the array, which part of the array you are looking at by doing target[0] or target[1] etc.



E.G. You have 2 transforms in the scene. One is called Player 1, the other Player 2. Under the Transform[] target, you have both player 1 and player 2... So when you say target.position, how does unity know you mean player 1, or even player 2? So to fix this you type target[0].position. That [0] will reference the first Player in the transform, in this case player 1. if you did [1] it would reference the seconds transform in the array, player 2 in this case.



You could also loop through each transform in the array and edit them like so.

                 Transform[] players = new Transform[2];
 
                 for (int i = 0; i < players.Length; i++)
                 {
                     players[i].position = new Vector3(0, 0, 0);
                 }

Error 2

Im looking at this part of the error now.

C:\Users\garre\OneDrive\Documents\Projects\Games\Beatdown\Assets\BoxerAI.cs 92 Active Error CS1503 Argument 2: cannot convert from 'float' to 'UnityEngine.Quaternion

Change float rotation = Quaternion.LookRotation(transform.position - transform.position); to Quaternion rotation = Quaternion.LookRotation(transform.position - transform.position); and that will solve your error message.


Extra info

Just as some extra information. i believe you are making an AI that can navigate to the player. In my opinion, working with rotations and Quaternions can be pretty tough. Try look at Unity's Navigation system. Navmesh. It handles movement for you and can go around objects, if they are in the way. It's really simple to set up.


Hope this helps and Good Luck ~ Jared

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

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

165 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 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 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 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 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 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 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 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 avatar image avatar image avatar image avatar image avatar image

Related Questions

Can't properly duplicate an enemy AI 0 Answers

Setting NavMesh from NavMeshTriangulation or Mesh 2 Answers

How can I make the enemy AI attack the player? 1 Answer

need help in script 1 Answer

Missing definitions and script error 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