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 LegionIsTaken · Oct 16, 2011 at 03:39 PM · instantiateaidynamicplacement

Dynamic placement of AI

Yo

I did some searching around, but it did not yield anything use full.

I would really like to know how one is supposed to create a dynamic Instantiation system, which automatically finds the next set of spawnpoints around you and spawn AIs. Let me brake it down for you my friend:

Theory:

  • Player passes a trigger called "Place_AI"

  • Find near by spawn points(empty gameObjects)

  • Instantiate enemys of different types at said spawn points

However I am having some trouble figuring out the details I guess.

When the player passes the trigger, how would one find the spawn points for AIs close to the players position without "hard coding" it? And how would one easily tell the computer to spawn 2 of these AIs and 3 of these AIs?

What I have now in basic is this:

 var count = 0;
 var enemy : Transform;
 
 function OnTriggerEnter (hit : Collider) {
     if(hit.gameObject.tag == "Place_AI"){
         count++;
         PlaceAI(count);
     }
 }
 
 function PlaceAI(count : int){
     switch(count){
         case count:
             Instantiate(enemy, saidSpawnPoints.transform.position, transform.rotation);
         break;
     }
 }

(I know there is a lot of redundancy, no need pointing that out ;))

But how would I find the spawns point relevant to my position dynamically? And how can I easily tell the computer to Instantiate x of these AIs and y of these AIs? While everything is as dynamic as possible(meaning not hard coded).

I hope you get what I am saying. I could really appreciate some help on this one.

Thank you.

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 syclamoth · Oct 16, 2011 at 03:48 PM 0
Share

For the exact locations of spawn points, I think you would have to 'hard code' it using empty transforms to designate appropriate places for AIs to spawn. This is to stop them from spawning in insane places like walls and in the air. Otherwise, it shoudn't be too hard to do it all in a trigger object which is connected to a bunch of spawn points- when you walk in the trigger, it makes things spawn, and then deactivates itself.

Also, you could have some kind of global registry of spawn points, and just find the 10 or so closest ones, that's another way of doing it.

1 Reply

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

Answer by DaveA · Oct 16, 2011 at 05:12 PM

What I do is have Spawnpoint objects (use the Editor to assign a nice icon for them), then assign them to an Array of Transform in my spawner script. There, you can pick random points, the 'next' point (round-robin), closest point, whatever. To find closest point, you loop through the array calling Vector3.Distance using the spawn point position from the array, and the current player position, keeping track of the smallest distance.

BTW You can also use the rotation of the spawnpoint object as the initial rotation of your spawned bot (or whatever). For this I have a gizmo that draws an arrow in that direction for ease of authoring.

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 john-essy · Feb 11, 2012 at 05:07 PM 0
Share

Well how would you keep track of the smallest distance?

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

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

I need to instantiate a empty gameObject 2 Units right/left of a 'Enemies' Transform? 3 Answers

need help in the instantiation script 1 Answer

Dynamic object Instantiate 1 Answer

Missing (Game Object) 3 Answers

What to set to make a Instantiated prefab a collider to trigger and event? 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