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 ImPvEspec · May 03, 2013 at 02:38 PM · random.rangenodes

Can I spread the destination of AI going towards a node.

Kind of struggled to word the question right, lets see if i can do it better here.

When I instantiate some enemies they're spread out all over the spawner and then head towards the node they're assigned too. However they eventually group up in single file which beats the objective of spreading them in the first place, I just want to know if I can apply the same random spread on the enemies when they reach the node, so they're grouping rather than lining up.

Here's how I'm currently random range spawning and how the AI move.

AI Spawning randomly around base.

 var node1 : Transform;
 var minionPrefab : GameObject;
 var timeDelay = 5;
 var range: float = 12;
   
 function Start () {
     spawnMinion();
     
 }
 
 function Update () {
      
 }
      
 function spawnMinion () {
     for (var x = 1; x < 8; x++) {
         yield WaitForSeconds(0.2);
         var pos = transform.position;
         pos.x += Random.Range(-range, range);
         pos.z += Random.Range(-range, range);
         var instance : GameObject = Instantiate(minionPrefab, pos, transform.rotation);
              if(x == 5 ) {
                  yield WaitForSeconds(timeDelay);
                         x -= 5;
              }
     }
 }

My AI Node is as follows (I'm working on the theory that i could apply the same random.range spread as I did with the spawning

 var forwardSpeed : float = 1;
 public var waypoint : Transform[];
 private var pointA : Vector3;
 private var currentWaypoint : int;
 
 private var wayDir : int = 1;
 
 
 function Update (){
    
        var target: Vector3 = waypoint[currentWaypoint].position;
        var moveDirection : Vector3 = target - transform.position;
        var velocity = rigidbody.velocity;
 
        if ( moveDirection.magnitude < 1 )
        {
          currentWaypoint += wayDir;
          
          if ( currentWaypoint >= waypoint.length )
          {
           currentWaypoint = waypoint.length - 1;
           wayDir = -1;
          }
          else if ( currentWaypoint < 0 )
          {
           currentWaypoint = 0;
           wayDir = 1;
          }
        }else{
                velocity = moveDirection.normalized * forwardSpeed;
        }
 
        rigidbody.velocity = velocity;    
 }
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

Answer by ATMEthan · May 03, 2013 at 02:48 PM

You have to apply some sort of spread to the position of the node, like what you did with your spawner. Right now you are telling all of your minions to move to that node's position. It doesn't matter where they start if you send them all the same position they will all end up on top of each other. But if you add a random offset per minion they will scatter around the node instead of being right on top of it.

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 ATMEthan · May 03, 2013 at 02:50 PM 0
Share

Note: You have to make sure all of the offsets are different per $$anonymous$$ion. If you don't you'll have the same problem you have now but the $$anonymous$$ions will end up at the node's offset position rather than the nodes position

avatar image ImPvEspec · May 03, 2013 at 03:20 PM 0
Share

Still can't figure it out, I'm playing around with a few of the things and they just keep lining up -_-

avatar image ATMEthan · May 03, 2013 at 03:46 PM 0
Share

try adding a random spread to the target variable in your AI Node script

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

13 People are following this question.

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

Related Questions

Start ambient audio tracks at random points? 2 Answers

Random.Range doesn't work 1 Answer

How can I define a box using Camera.ScreenToWorldPoint? 2 Answers

How can I change textmesh to a random text snippet? 1 Answer

Instantiating an Object doesn't use the given position. 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