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 bscerri · Sep 05, 2012 at 09:00 AM · aiwaypoints

How do I spawn unique Waypoints for my AI?

Greetings,

I'm currently working on a prototype for a Petri dish-like simulator. In it, the player, a microbe, moves around and collides with other Microbes to spawn yet more Microbes. These are all of different colours, with the new Microbes spawning as a colour between the two "parents".

My question is, how do I have the newly Instantiated Microbes interact with their own Waypoints? I can individually plug each Microbe with a Waypoint in the Editor, but when I launch, and new Microbes spawn, they either go towards another Microbe's Waypoint, or they do not move (depending on the various things I have tried).

My code looks like this:

(MOVEMENT FOR THE MICROBES)

 public GameObject Waypoint;
 
 void Update () 
 {
     transform.LookAt(Waypoint.transform.position);
     if(Vector3.Distance (transform.position, Waypoint.transform.position) >= 2)
     {
         transform.Translate (Vector3.forward * 2 * Time.smoothDeltaTime);
     }
     if(Vector3.Distance (transform.position, Waypoint.transform.position) <= 2)
     {
         Waypoint.transform.position = new Vector3(Random.Range(-10F, 10F), 0.75F, Random.Range(-10F, 10F));
     }
 }

And the Instantiate Script on the Player is (this is an example of a Blue player hitting a Yellow Microbe, and creating a Green Microbe):

 void OnCollisionEnter(Collision Microbe)
 {
     if(Microbe.gameObject.tag == "Yellow")
     {
         Instantiate (MicrobeGreen, new Vector3(Random.Range(transform.position.x - 2.5F, transform.position.x + 2.5F), 0.75F, Random.Range(transform.position.z - 2.5F, transform.position.z + 2.5F)), Quaternion.identity);
     }
 }

Could you please help me out? I can't figure this out, and I've been working on it for a while now :/

Thanks!

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
1

Answer by fafase · Sep 05, 2012 at 09:06 AM

I think your issue can be fixed with function Start(). You would search and find the waypoint you want your object to go to. The Start function is called when the object is instantiated.

If you want your guy to go to waypoint2 and waypoint4 and another to go to waypoint3 only:

 var waypoint:GameObject[]=new GameObject[2];
 function Start(){
 waypoint[0] = GameObject.Find("Waypoint2");
 waypoint[1] = GameObject.Find("Waypoint4");
 }
 
 var waypoint:GameObject;;
 function Start(){
 waypoint = GameObject.Find("Waypoint3");
 }

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 Fattie · Sep 05, 2012 at 09:55 AM 0
Share

excellent answer, yes I believe conceptually what he is looking for is the "Start()" function, he could learn about Awake() as well

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

Why isn't a Ai Waypoint Spawning??? 0 Answers

Problems with my waypoints code 1 Answer

Waypoints and out of range problem.[Solved] 1 Answer

Make player follow waypoints, but still control it's X axis 3 Answers

What is the best AI system for pathfinding on a moving platform 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