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
1
Question by ta2909i · Apr 12, 2015 at 10:08 AM · aienemyteamtargettingbehavior

Nearest Enemy To Team (Without Crowding!)

Hi all,

I have a script to assign the nearest enemy to each of my 3 team players. However I do not want team members to crowd to the same enemies.

They should distribute themselves evenly otherwise they will get picked off as they all focus on one enemy.

I can run the find nearest script multiple times and each asking the team players to ignore an enemy character that is closer to another team-mate. However this seems like a very heavy process to run each frame.

Any suggestions, is there a better way to do this?

T

Comment
Add comment · Show 2
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 ta2909i · Apr 09, 2015 at 07:19 PM 0
Share

...just to add. I am guessing its safe to assume that $$anonymous$$m players won't target the same enemy at the same frame.

avatar image meat5000 ♦ · Apr 12, 2015 at 10:08 AM 0
Share

Ins$$anonymous$$d of finding just the closest, why not find the closest three and distribute them?

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by AlwaysSunny · Apr 10, 2015 at 10:10 PM

You can assume that if the code responsible for saying "this ones already taken" executes prior to the next sweep. So unless you're pausing during that sweep operation, you are correct.

Consider creating a large trigger attached to your seeker objects. The objects found during OnTriggerStay(){} are the objects in the seeker's vicinity. You can query those objects for whatever - name, tag, layer, script - and use that to make decisions. This is a decentralized approach to management.

Sometimes it makes more sense to track objects and compare the objects to one another without using triggers. This implies you have some kind of all-seeing script tracking (keeping references to) all your agents. By looping over groups of agents, you can make decisions and apply logic to them. This is a centralized management style.

You should use both interchangeably (they compliment each other) based on which makes more sense in a given case, but I like having an all-seeing script in any project. (In practice it's usually many scripts with a common point of access like a singleton "parent").

Using Finds() every frame is really never a good idea. They are the weakest possible approach to reference management. You might get away with it on small test projects, but it should not be treated as a primary tool for tracking references.

Simple decisions like this are okay without using a service, but eventually you may want more complex "group decisions" - these can be handled by making requests to a service which can examine the situation based on data passed in by group members.

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

My Eneny AI Script Wont Work? 2 Answers

How can i Learn Basics of Rain AI 1 Answer

Guard AI acting quite weird - Please Help! 1 Answer

how to make a basic AI script in a short time 2 Answers

Enemy following the target with ITween 2 Answers


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