- Home /
 
Simple Waypoints Glitch
So I have a system of waypoints where the player from Point A to B to C to D etc...
This system works fine. I can get from A to B to C no problem. However, I can't go backwards. That is, I can't go from C to B to A.
The way my code works is that at any one point, there is Node 1 and Node 2, the player is between the two. When the player reaches Node 2, Node 2 becomes Node 1 and the next node in the array, let's call it Node 3, becomes Node 2. Here is the code. (C#)
         if (Mathf.Abs (Nodes[Node2].transform.position.y - transform.position.y) < 0.1) {
             if (Railroad == true){ //Whether or not player movement is govered by waypoints
                 if (Node < NodesNumber){ //makes sure player is not at the end of the waypoints array
                     if (IsNext == false){ //prevents this code from repeatedly spamming because the player is in proximity to a node
                         Node = Node + 1; //switches nodes
                         rigidbody2D.velocity = Vector2.zero; //Stops player movement
                         IsNext = true; //prevents spam
                         Debug.Log ("Test");
                     }
                 }
             }
         }
         else if (Mathf.Abs (Nodes [Node].transform.position.y - transform.position.y) < 0.1) {
             if (Railroad == true){
                 if (Node > 0){ //prevents code from repeating itself.
                     if (IsNext == false){
                         Node = Node - 1;
                         rigidbody2D.velocity = Vector2.zero;
                         IsNext = true;
                         Debug.Log ("Test2");                        
                     }
                 }
             }
         }
     if (Mathf.Abs (Nodes [Node].transform.position.y - transform.position.y) > 0.1) {
         IsNext = false;
     }
 
               From my own attempts at debugging, I can tell you that when the player gets to Node 2, the first function works fine. However Node 1 triggers both functions simultaneously, resulting in a net change of nothing. In other words, the top function occurs whether or not it is Node 1 being touched. This is not the case with the bottom function. What I think happens is that when Node 1 is touched, it becomes Node 2, as it is supposed to, however for some reason, the IsNext variable isn't preventing the first function from turning what would be Node 2 back into Node 1.
So what do?
Your answer