Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 Ppa0 · May 19, 2011 at 06:31 PM · gameobjectvector3aiwaypoint

Help With Simple Waypoint System

Hey guys I have made a simple waypoint function but I am having a bit of trouble. What I want it to do is this:

locate closest waypoint, go to it, if it reaches it, search again without including the one its currently on.

As you can see in the code below: (distanceToWayPoints[closest] < totalDistance) that block of code has to be changed

 void WayPoint()
 {
     // total distance
     int totalDistance = 10;
     
     // goes through all the waypoints
     for (int nStart = 0; nStart < MaxNoOfWPs; nStart++)
     {
         // calculates all the distances from the monster to each waypoint
         distanceToWayPoints[nStart] = Vector3.Distance(everyWayPointInLevel[nStart].transform.position, transform.position);
         
         // if its the closest waypoint than have it be the target
         if (distanceToWayPoints[nStart] < distanceToWayPoints[closest])
         {
             closest = nStart;
             target = everyWayPointInLevel[closest].transform.position;
 
             //used as temp to know which one was the last wp
             lastWayPoint = everyWayPointInLevel[closest].transform.position;
         }
         
         // if the enemy gets close enough to the waypoint, trigger this = 
         if (distanceToWayPoints[closest] < totalDistance)
         {
             // THIS HAS TO BE CHANGED
             // so that instead of placing the wp at 0,0,0
             // it makes it not calculate the wp in the search
             everyWayPointInLevel[closest].transform.position = new Vector3(0,0,0);

         }
     }
     // animation
     animation.CrossFade("walk");
     // speed
     speed = walkingSpeed;
 }    
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

0 Replies

· Add your reply
  • Sort: 

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

1 Person is following this question.

avatar image

Related Questions

Help with a simple AI 2 Answers

Kind of Patrol AI with Point A and B Help 1 Answer

How am I supposed to use SetTile( ) on a GameObject's position if its x and y values aren't integers? , 1 Answer

Destroying an instatiated game object with a script attached creates problems for the rest of instatiated game objects with the same script 0 Answers

Check whether car has passed a point in world space 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