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 hotozi · Jul 24, 2012 at 12:57 PM · triggerenemylookatattach

MAke an enemy attack and look at other enemies HELP?

i made an enemy that look at the player and attack the player but i want to know how to make an enemy that can attack and look at other enemies...the other enemies are taged as ''enemy'' so....?

Comment
Add comment · Show 1
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 irrationalistic · Jul 24, 2012 at 05:41 PM 0
Share

Your look at and attack code should be the same, just be able to accept a new target. Then, if you want your enemy to attack the closest player or enemy, just find a list of the nearest guys using Physics.OverlapSphere and pick the closest one as the target.

1 Reply

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by DESTRUKTORR · Jul 24, 2012 at 05:52 PM

Personally, I find tags to be a bit sloppy, for this very reason, and because, quite frankly, I don't know how much processing power it takes to search through them (or what extra functionality that I don't need that it does anyway).

When you're scripting, you should just have them cycle through everything with the tags for the player, and enemies (and anything else you want them to aggro to), and pick them, accordingly, based on aggro.

For instance, if you want them to prioritize attacking the other enemies, over the player, have them switch to the closest one.

Essentially, I'd go about it starting with a list (dictionaries work, too, but I prefer lists, when I don't need the extra "finding power"), and cycle through all the GameObjects tagged with the various tags you wanted to use, and adding all of them to the list (potentially skipping "dead" ones, or "friendlies" for those enemies), then choosing a target to face and attack, based on weights that you want to use.

Just off the top of my head, some "aggro weighting" methods might use distance (attacking the closest enemy/player, first), damage amounts/influence (attacking the enemy/player that has dealt the most damage/healing/buffing/debuffing/etc.), or specific types of enemies/players might get higher weight, automatically.

For the best gameplay experience, I'd suggest using some combination of these things. If you need help with scripting this, just leave a comment and I'll edit in some code to show you how I'd go about doing it.

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 irrationalistic · Jul 24, 2012 at 05:55 PM 0
Share

Layers and Layer$$anonymous$$asks will help make it easier to use physics-based detectors ins$$anonymous$$d of tags. This means your enemies could be on the "Enemy" layer and then have tags that help to define more properties, or even have an Enemy component to request the data for the "aggro weighting."

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

6 People are following this question.

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

Related Questions

Multiple Cars not working 1 Answer

How to trigger a Script from an Object. 0 Answers

Trigger to make another trigger to appear? 2 Answers

What’s wrong with my Safe Volume (safe zone) code? 0 Answers

enemy spawn and in game time counter 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