• 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 EmpI · Aug 08, 2014 at 12:23 AM · movementplayerpath

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?

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

Player Going Backwards on Waypoint Path Issue 0 Answers

how to move along path with user controll 0 Answers

player move while mouse move. 0 Answers

Terrain Slope Bouncing 1 Answer

Charactercontroller won't go down, only goes up 0 Answers

  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges