• 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 Tabu · Oct 26, 2012 at 09:56 PM · randompathfindingwander

Random wandering not so random

I have been trying to figure out what is wrong for a while now, but I am still completly clueless.

I am trying to get creature walk around randomly on a landscape. My problem is, that for some reason, all creatures always end up walking to one specific corner of the landscape, it is not apparent right away, but after a while all creatures is just in one corner.. it is as if the random, is "more random" in a specific direction.. its the same corner for all sessions, and it is the same for all creatures. If anyone know what is going on, please help me.

Here is the method

 public void Wander ()
 {
  destination = transform.position + Random.onUnitSphere * wanderDistance;
  destination.y = 100f;
  Ray ray = new Ray(destination, Vector3.up*-1);
  Physics.Raycast(ray, out hit);
 
   if(hit.collider == null)
    return;
         
   if (hit.collider.gameObject.tag == "Terrain") {
    destination.y = hit.point.y;
   }
 
   //tempObject.transform.position = destination;
   navMeshAgent.SetDestination (destination);
   isWalking = true;
  }
Comment
Add comment · Show 4
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 hvilela · Oct 26, 2012 at 10:54 PM 1
Share

How do you call wander? Just once, every X seconds, every time the creature reaches the last destination... ?

And could you send a print of you terrain with the creatures in the corner? A top view with the entire terrain would be great.

avatar image Owen-Reynolds · Oct 27, 2012 at 03:09 AM 1
Share

When they all get to the corner, are their `destination` vars also in that corner? Destination might be nicely random, with the bug in the walk routine.

avatar image Tabu · Oct 27, 2012 at 07:55 PM 0
Share

Wander is called approx every 1 seconds, it is the main method for moving.. however, if they are hungry, they will go looking for food, I did not think much of this.. but maybe actually this is what causes it? (I am experimenting with it right now) I did not consider this to be a factor, until I read your comments. when creatures are hungry, they will look for food in an area. If they find anything an array of food is created, and the creature chooses the first available from the array. I made a movie showing the pattern, somehow, the breeding part have broken, so the race will die out, but I think it shows the tendency.. going from top right to bottom left... this is the case every time. http://realitylag.com/temp/Evolution.mp4

avatar image Tabu · Oct 27, 2012 at 08:16 PM 0
Share

It looked like it was in fact the looking for food that did it. We used a overlapsphere and then just took the first collider in the array.. this apparently caused the creatures to slowly but surely go in one direction.. I guess that overlapsphere starts in the same direction when gathering objects?

Thank you all for your time...

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Montraydavis · Oct 27, 2012 at 03:32 AM

As mentioned before, it is your destination. They all come out to be the same in value. Perhaps multiply it by a random value.

 destination = transform.position + Random.onUnitSphere * wanderDistance * Random.Range ( 1, 100 );
Comment
Add comment · Show 2 · 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 hvilela · Oct 27, 2012 at 03:34 AM 1
Share

Who said it's in the destination?

avatar image Owen-Reynolds · Oct 27, 2012 at 04:01 PM 1
Share

Look at `Random.onUnitSphere`. It gives a random 3D direction. Then the rayCast to place it on the ground effectively gives it a random distance 0 to $$anonymous$$ax. Ex: a more up/down random sphere point gets ground rayCast closer to you.

But, yeah, I would have used `dest= me + Quat.EulerA(0, Rand(360), 0) forward Rand(5,20);`

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.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

11 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

Related Questions

help: pathfinding in random maze. 1 Answer

Flight Path Generator Troubles 0 Answers

AI Pathfinding 1 Answer

Random Wander Ai 0 Answers

Onclick Waypoint Wander 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