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 /
This question was closed Sep 27, 2014 at 10:27 PM by DeadKenny for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by DeadKenny · Sep 25, 2014 at 08:02 PM · arrayplayerailistwaypoints

Waypoints and out of range problem.[Solved]

Ok I have this AI over here thats a bit retarded at the moment and this is caused by it not being able to loop its waypoints.

As in it gets to the end of the last way point fine but then throws up the out of range exception. I need a way for it to make the current way point the first in the array again when it gets to the end.

Can you help me with a solution, I have been trying everything and they not working here is the code that so far.

      if(inWaypointPath == true && curWaypointDist < 2){
 
              currentWaypoint = currentWaypoint+1;
 
         
         }
 // this is what is not working... This is just one way I tried but failed.
     if(currentWaypoint > wayPoints.Count){                
                 
             currentWaypoint = 0;
 
          }

Thanks.

Comment
Add comment · Show 1
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 betaFlux · Sep 26, 2014 at 03:16 AM 2
Share

Have you tried if(currentWaypoint >= wayPoints.Count) or if(currentWaypoint > wayPoints.Count -1) or even .Count +1? just to be on the safe side. How do you actually use "currentWaypoint"? Like this?: wayPoints[currentWaypoint].position

1 Reply

  • Sort: 
avatar image
1
Best Answer

Answer by Chris_Dlala · Sep 26, 2014 at 10:57 PM

Hi, @betaFlux is correct if you are using the array as expected. You are checking if the incremented index is past the last index in the array and then wrapping it around to the first index (0). The problem is that this will not reset the index to 0 until it is greater than the count but wayPoints[wayPoints.Count] will be out of bounds due to indexing from 0.

     if(currentWaypoint >= wayPoints.Count)
     {              
         currentWaypoint = 0;
     }

I hope that helps =D

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 DeadKenny · Sep 27, 2014 at 10:27 PM 0
Share

Alright thanks to both of you guys it worked.

Thank you very much.

Follow this Question

Answers Answers and Comments

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

Related Questions

A node in a childnode? 1 Answer

Follow Player Via Waypoints 1 Answer

Array out of range 1 Answer

Object Pool only activating one prefab 1 Answer

Disable All Transform In List 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