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 Tyrebear · Jan 22, 2014 at 11:10 AM · airandompathfindingwaypoint

How can I make AI follow waypoints and choose random ones?

Hello I am making a 2d Isometric management game. When customers enter the restaurant I want them to either head towards the front registers or go to the vending machine. I am able to make the customers walk to the door but I do not know how to make them seek out the next way point. I am also unable to get them to navigate around objects or choose between a random point that I set. Its kind of difficult to explain so here's some visual aid. alt text

point explanation.jpg (240.0 kB)
Comment
Add comment · Show 3
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 ahaykal · Jan 22, 2014 at 11:45 AM 0
Share

But you will have to show us what you started with. Show us your sample script. Where are you stuck how are you moving him in the first place etc...

avatar image nesis · Jan 22, 2014 at 01:17 PM 0
Share

Since you're using a tiled map, I'd suggest looking up how to implement A* pathfinding (also known as AStar). It takes a bunch of nodes (your tiles) that are linked / blocked from one another in whatever way, and does a quick search to find a path from A (eg your door) to B (eg your registers or vending machine).

The Unity asset store has a free A* package, but I'm not sure that it'd fit your needs. It'd be good to understand how A* works, so google a little and see what you can find :)

avatar image Tyrebear · Jan 23, 2014 at 12:44 AM 0
Share

Thanks ahaykal and nesis. To make the customer seek out a point i just have a speed variable that translates based on Time.deltaTime. Then if the customer reaches a point I increment the currentPoint variable by 1. The problem with this is that the customers wont avoid objects and its difficult to randomize their paths. I've looked into A* and it seems pretty robust. I managed to generate a graph of my map that analyses what areas are walk able but so far I can only get the customer to seek out a single point or object. I could still use some help.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Tyrebear · Feb 02, 2014 at 12:07 AM

 var waypoints : Transform[];
 var waypoint : Transform;
 var speed : int;
 var currentWaypoint : int;
 var agent : NavMeshAgent;
 var isMoving : boolean = false;
 var customer : GameObject;
  
 function Update () {
 waypoint = waypoints[currentWaypoint];

 if (isMoving == true){ // sets the active waypoint to the next currentwaypoint
 agent.SetDestination(waypoint.position);
 }
 }
  
 function OnTriggerEnter (other : Collider) {
 if (other.tag == "Waypoint"){
 currentWaypoint++;
 }
 if (currentWaypoint == 5){
     Destroy(gameObject);
     }
 if (other.tag == "Waypoint" && currentWaypoint == 2){
 currentWaypoint = Random.Range(2, 4);
     }
 }
  
 function WaitAtPoint(){
 isMoving = false;
 yield WaitForSeconds(5);
 }

After not being able to really find a definitive answer online I created my own script.

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 marlon_1_23 · Sep 12, 2017 at 02:03 PM 0
Share

Thanks, your one line of code :

currentWaypoint = Random.Range(2, 4);

solved my problem!

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

22 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

AI Pathfinding 1 Answer

Wandering enemies 1 Answer

Incredibly high speed tweening/enemy movement 0 Answers

Enemy detection while pathfinding through the map 1 Answer

Why isn't a Ai Waypoint Spawning??? 0 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