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 · Nov 13, 2012 at 05:24 AM · pathfindinghowreversenode

How can I reverse my node list?

So this script is for 5 different AI that basically go from a vending machine to their desk but i want them to come back again in the same order they went there. Each AI has about 5 nodes, i've tried a few things but yea its driving me nuts..

 var forwardSpeed : float= 1;
 public var waypoint : Transform[];
 private var pointA : Vector3;
 private var currentWaypoint : int;
 
 
 function Update () {
     if(currentWaypoint < waypoint.length){
     var target: Vector3 = waypoint[currentWaypoint].position;
     var moveDirection : Vector3 = target - transform.position;
     var velocity = rigidbody.velocity;
         if(moveDirection.magnitude <1){
         currentWaypoint++;
         }
         else{
         velocity = moveDirection.normalized * forwardSpeed;
         }
         rigidbody.velocity = velocity;    
         }
      
 }
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 ImPvEspec · Nov 13, 2012 at 06:03 AM 0
Share

sorry took so long.. yea that confuses me a tad, not that great at program$$anonymous$$g but i assume its this line else{if(loop){currentwaypoint=0;}}} im looking for, because if i could not use ur entire script i get addition points for using my own stuff ins$$anonymous$$d on pinching yours

avatar image deltamish · Nov 13, 2012 at 06:06 AM 0
Share

so should i post a simpler script

avatar image ImPvEspec · Nov 13, 2012 at 06:12 AM 0
Share

if you would be so kind i honestly thought it would be something as simple as (blahblah).Reverse lol .Guess not its just a 2D isometric game for a rapid protype and yea reversing the path is pretty much all i have left... as long as they travel between the desk and vending machine via a route of atleast 5 nodes im happy

3 Replies

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by AlucardJay · Nov 13, 2012 at 07:19 AM

I have tested this and it is working. I included a variable to change whether the waypoint count is going up or down (wayDir), then 2 checks if currentWaypoint > waypoint.length or < 0.

 #pragma strict
 
 var forwardSpeed : float = 1;
 public var waypoint : Transform[];
 private var pointA : Vector3;
 private var currentWaypoint : int;
 
 private var wayDir : int = 1;
 
 
 function Update () 
 {
     //if ( currentWaypoint < waypoint.length )
     //{
         var target: Vector3 = waypoint[currentWaypoint].position;
         var moveDirection : Vector3 = target - transform.position;
         var velocity = rigidbody.velocity;
         
         if ( moveDirection.magnitude < 1 )
         {
             currentWaypoint += wayDir;
             Debug.Log( "currentWaypoint " + currentWaypoint );
             
             if ( currentWaypoint >= waypoint.length )
             {
                 currentWaypoint = waypoint.length - 1;
                 wayDir = -1;
             }
             else if ( currentWaypoint < 0 )
             {
                 currentWaypoint = 0;
                 wayDir = 1;
             }
             
             Debug.Log( " : currentWaypoint " + currentWaypoint + " : wayDir " + wayDir );
         }
         else
         {
             velocity = moveDirection.normalized * forwardSpeed;
         }
         
         rigidbody.velocity = velocity;    
     //}
 }
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 ImPvEspec · Nov 13, 2012 at 07:27 AM 0
Share

well it wont let me thumbs it for some reason but it works thank you so much.. I havnt come across wayDir yet but something for the memory .

And thanks delta for trying to help appreciate the effort

avatar image AlucardJay · Nov 13, 2012 at 07:32 AM 0
Share

I think you can only thumb (like) when you have enough karma. To accept the answer, just click on the tick under the thumbs, the answer then should have a green background (and your karma rises by accepting answers!).

wayDir is just a variable I made up. It is simply a value of +1 or -1.

So if wayDir == 1 then currentWaypoint += wayDir; means currentWaypoint += 1; (or ++)

Then if wayDir == -1 then currentWaypoint += wayDir; means currentWaypoint += -1; (or --)

It just changes the direction of the count when you use currentWaypoint += wayDir; either going up or down (thats why I left the Debugs in, to demonstrate currentWaypoint going up then down).

(wayDir is my abbreviation for Waypoint Direction !)

=]

avatar image
0

Answer by deltamish · Nov 13, 2012 at 05:35 AM

Hi, What are you are trying to do is called waypoint looping I have posted a script for the above here It is an AI script

read the Update function of my script it contains looping to test it just copy the required code excluding animation code if you wish.it may seem a bit long but it is a very simple one.The animation code is making it long

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 deltamish · Nov 13, 2012 at 05:38 AM 0
Share

if you are feeling confused i shall post another script for you only looping and moving part

avatar image
0

Answer by deltamish · Nov 13, 2012 at 06:37 AM

okay heres a simple script

 var waypoint:Transform[];
 var currentwaypoint:int;///Sets the number to infinity
 
 var loop:boolean = false;
 
 var character: CharacterController;
 
 var rotationspeed:float = 1.9; 
 
 function Update(){
 
 if(currentwaypoint < waypoint.Length){
 
 var way = waypoint[currentwaypoint].position;///start of detecting waypoint pos
 
 var direction:Vector3 = way - transform.position;
 
 if(direction.magnitude < 1){
 currentwaypoint++;
 character.Move(direction.normalized * walkspeed * Time.deltaTime);

 //////////to rotate to wards the waypoint(optional)///////
     transform.eulerAngles = Vector3(0,transform.eulerAngles.y,0);
     transform.rotation = Quaternion.Slerp(transform.rotation,Quaternion.LookRotation(direction),rotationspeed * Time.smoothDeltaTime);  
     /////////////////////////

 }////end of detecting waypoint pos 
 } else {/////detecting wether to loop or not
 
 if(loop){
 currentwaypoint = 0;
 }
 }///end of detecting loop
     }////end of update

I have given a lot of space between the codes to make them easier to understand Sorry for the late reply

Comment
Add comment · Show 4 · 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 ImPvEspec · Nov 13, 2012 at 06:48 AM 0
Share

unknown identifier walkspeed should i just add a variable var walkspeed:float = 1.9;

avatar image AlucardJay · Nov 13, 2012 at 06:51 AM 0
Share

@deltamish : Edit your other answer with this information, don't post 2 answers :/

@ImPVEspec : I cannot read your code. For further help, please format your code in the question. You can do this by highlighting all your code, then clicking the 10101 button at the top of the edit window.

Though, it may be easier just to delete the code, paste it in again from the source, then highlight all the code and press the 101010 button at the top of the edit window before posting.

avatar image ImPvEspec · Nov 13, 2012 at 07:00 AM 0
Share

sorry i didnt know that
@deltamish i dont have anything to put in the var character: CharacterController; sorry i dont mean to be nub

avatar image AlucardJay · Nov 13, 2012 at 07:17 AM 0
Share

No problem, it is much easier to read now =]

I have submitted an answer ($$anonymous$$ $$anonymous$$ay)

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

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

A* Algorithm Node Grid Generation 2 Answers

A* endless loop 0 Answers

Making a list of list of nodes for Kruskal 2 Answers

How can I manually link/unlink a node in a path? 0 Answers

Node Pathfinding 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