Switching from one path to another means object always starts at Waypoint 0



  • @Baroni You're right, the scripting reference is back. Your SimpleWaypointSystem.pdf is only 6 pages, so the scripting reference is essential for me!

    I've uploaded the project here:


    I just RARed the folder, it's not a .unitypackage, hope this is easy.

    Go to your Example2_Bezier scene and click the sphere I made. There's a script attached called SplineProblem.cs and your SplineMove is also on it. Hit Run and you can press 1 and 2 on the Keyboard to make it jump on two of your example splines, at a set point - and choose forward/back. You'll see.

    Once my reverse bool is checked the trouble starts; not saying my code is right but it just seems that when the Reverse bool is set in SplineMove it flips it from reverse to forward every time it's set. In my game, my spline network works fine as long as objects jump onto splines going forwards.

    I tried to PM you the link but the board doesn't have the facility. I see from your profile you're only 18, which means you launched SWS when you were 8, pretty impressive, I could only program in BASIC when I was that age.



  • Although this is a semi-restricted forum, please do not post links to full files from our assets. I wrote 'via email' before 😉

    I will have a look at it later today, thanks.



  • @Baroni Sorry; my SMTP can't send an e-mail as big as the project; OK I could change the settings though.

    Anyway: now I can access your codebase I looked up Reverse:
    https://www.rebound-games.com/docs/sws/splineMove.html#ae1b551cc51c9d556342b27b466a7c7cb
    now I can see it says "Reverses movement at any time." I was trying to use it as an instruction to go backwards on the spline - how could I do that?



  • @Shin_Toasty said in Switching from one path to another means object always starts at Waypoint 0:

    @Baroni Sorry; my SMTP can't send an e-mail as big as the project; OK I could change the settings though.

    Send the link via email, just do not post it here. Btw the link seems to be dead now so I did my own tests:

    1. Define Reverse+startPoint before running the game:
      Set the values in the inspector. E.g. when startPoint is set to 2, the object always starts at the same waypoint, reversed or not.

    2. Set Reverse+startPoint via code, object is or is not moving:

    moveRef.Stop(); //stop script first if object is moving
    
    moveRef.startPoint = 2;
    moveRef.reverse = true; //or false
    moveRef.StartMove();
    
    1. Switch Reverse at any time while moving, also in between waypoints:
    moveRef.Reverse();
    

    @Shin_Toasty said in Switching from one path to another means object always starts at Waypoint 0:

    "get on spline A at point B and move forwards or backwards."

    All of the above approaches work as expected. In regards to the above goal, you would either use 1. or 2. depending on used at runtime or not.



  • @Baroni OK, I wasn't doing currentSpline.Stop(); first, but the second time your code above is run, if moveRef.reverse= true, it will of course be reversed again and appear at the other end going the other way.

    Can I code a function that can initialises a backward movement along a specified spline, from a specified point every time it runs? This is what I'm trying to do. I'm not actually saying there is a bug!

    Here's my code (I have to use code) and it's the same as yours really: the second time I run it

    public void GetOnSpline()
      {
          currentSpline.Stop();
          currentSpline.startPoint = 5;
          splineName = "Path2-1 (Loop)";
          currentSpline.reverse = true;
          currentSpline.SetPath(WaypointManager.Paths[splineName]);
      }
    

    reverse is true, so it starts at the opposite place & in the opposite direction. The third time = right place right direction, fourth = opposite again and so on.

    I asked before if I was doing things in wrong order ?

    I have just deleted the RAR file - I don't think you need a whole project; the few lines of code in this post is all that matters really.



  • @Shin_Toasty said in Switching from one path to another means object always starts at Waypoint 0:

    @Baroni OK, I wasn't doing currentSpline.Stop(); first, but the second time your code above is run, if moveRef.reverse= true, it will of course be reversed again and appear at the other end going the other way.

    This is not true. My code (point 2, not the public Reverse method) which is not that different from yours, always places the object at the second waypoint and then going left (depending on the camera angle). I do not change the reverse flag - it always stays at true, thus always starting at the same point walking in the same direction.

    Are you sure you do not change the reverse bool every time you call the method? I don't understand what you mean by "the second time I run it reverse is true" - in your method reverse is always hardcoded to true. At the first time, second and all other calls. It doesn't change unless you do it.



  • @Baroni I have re-uploaded the project and e-mailed you the link.

    Yes it's always true, I was just saying that it being true causes it to flip flop between true and false. Makes no sense to me either.

    I have a feeling this may be a DOTween problem and that I'm "digging in the wrong place".



  • Thank you for the project! I did my tests with a normal spline path instead of a bezier path as in your example... sorry for that, I forgot that you mentioned bezier paths some time ago :(

    In the BezierPathManager implementation of GetPathPoints, a reference was passed over instead of a new copy. Which meant that the reverse logic always worked on the same array, reversing it over and over again. Please replace the method (in BezierPathManager.cs) with the following code:

            /// <summary>
            /// Returns waypoint positions (path positions) as Vector3 array.
            /// <summary>
            public override Vector3[] GetPathPoints(bool local = false)
            {
                Vector3[] newPathPoints = new Vector3[pathPoints.Length];
    
                if(local)
                {
                    for (int i = 0; i < newPathPoints.Length; i++)
                        newPathPoints[i] = transform.InverseTransformPoint(pathPoints[i]);
                }
                else
                {
                    pathPoints.CopyTo(newPathPoints, 0);
                }
    
                return newPathPoints;
            }
    

    All of your "SplineProblem" methods then look fine to me. Thanks for your patience!



  • @Baroni Thanks. So my big bug is fixed now and the little startPoint indicator one is too. I can code my game. :)

    I did mention Beziers from post 2 onwards and I also asked if the bug was caused by an iterator going wrong, but I didn't explain the problem well overall. Your codebase's definition of Reverse confused me too: I thought that meant it was supposed to toggle forward/backward when true.

    Maybe you should add a GetOnSpline() example in your Bezier demo scene? People might find being able to jump to any spline at any startpoint and move in either direction useful.

    I haven't found anything else wrong with SWS but if I do I will start a new thread - but also e-mail you a project. SWS is a great asset, especially for an 18 year old. Will I leave you a 5* review? As Stiletto says, https://youtu.be/WiwMmu5E_KE?t=155



  • Thanks for the feedback, I'll sneak a "jump to point + reverse" sample into the next update.

    I'm not really 18, that must be the default value ;) In a few years double of that...


Log in to reply