• 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 09, 2014 at 03:09 AM · movementplayerpathwaypoint

Player Going Backwards on Waypoint Path Issue

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 etc 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 am I doing wrong?

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

Simple Waypoints Glitch 0 Answers

Rotate, follow randomly generted waypoints? 2 Answers

how to move along path with user controll 0 Answers

,Look rotation viewing vector is zero and character always facing 1 direction when idle 0 Answers

Using Navmesh for Player navigation 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