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 daymont87 · Jan 10, 2013 at 04:41 PM · targetaimissueslook

Look at issues

Hello guys! I use this script below for automatic aiming at the nearest target. It works briliant, but i have one issue, - my character also must have tag "Player1", and of course if i set it - he begins to aim into itself. How can i make, that my character aim to all other target with tag "Player1", excluding himself? Or maybe exist better way get similar effect?

 function Update() {
     var waypoints: GameObject[] = GameObject.FindGameObjectsWithTag("Player1"); 
     var closest: GameObject; 
     var closestDist = Mathf.Infinity; 
 
     for (waypoint in waypoints) { 
         var dist = (transform.position - waypoint.transform.position).sqrMagnitude; 
 
         if (dist < closestDist) { 
             closestDist = dist; 
             closest = waypoint; 
             } 
     } 
     transform.LookAt(closest.transform);
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
Best Answer

Answer by Geo.Ego · Jan 10, 2013 at 04:53 PM

The correct way to do this is to have a different tag for your targets. The reason that you tag objects is to tell them apart; when you tag them all the same, you'll treat them all the same. Make your player "Player1" and give the targets another tag; adjust your script accordingly.

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 daymont87 · Jan 10, 2013 at 06:15 PM 0
Share

Ok, can you say, how i can fix error "IndexOutOfRangeException: Array index is out of range.LookAt.Update () (atAssets/Weapon/Script/LookAt.js:19)" it appeared afterward i destroy my target, obviously i must check destroyed my target already, or not, but how?)

avatar image Geo.Ego · Jan 11, 2013 at 05:01 AM 0
Share

I can't say precisely without seeing your code, but that exception refers to an attempt by your code to reference an array index that is outside of the range of the array. For instance, if you four events in your array and you try to access the fifth, you will get this exception. Look for somewhere that your code has the potential to do that. If you are still having the issue, start a new question with as much detail as possible.

avatar image Geo.Ego · Jan 11, 2013 at 05:01 AM 0
Share

I can't say precisely without seeing your code, but that exception refers to an attempt by your code to reference an array index that is outside of the range of the array. For instance, if you four events in your array and you try to access the fifth, you will get this exception. Look for somewhere that your code has the potential to do that. If you are still having the issue, start a new question with as much detail as possible.

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

9 People are following this question.

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

Related Questions

Make the turret automatically rotate to look at where the crosshair is aimed at. 3 Answers

How to ensure multiple weapons fire towards the same target? 1 Answer

Look at +1z of target and move to -1z of target? Almost there! 2 Answers

Look at target and flip 1 Answer

target tracking with lead time 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