Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Freewalk mode, then return to spline
#3
(08-27-2018, 02:25 PM)_Aka_ Wrote:
(08-27-2018, 03:39 AM)mythstified Wrote: It will find the nearest CP through a simple distance calc; it will InsertBefore that nearest CP with the position at the players current position; once it reaches the CP first found, it will remove the 'virtual' one I created to smooth out the path, and the original spline should look the same.
Could you please send me the code that does that so I can see what goes wrong? Also, what Curvy version do you use? And if you have a ready made scene/project to test this, that would save some time.

Unfortunately it might be a bit tricky for me to engineer a test scene for this issue, but maybe you can look at my code and see what's wrong?

Code:
   public void toggleFreeTurning()
   {
       if(isFreeTurning)
       {
           isFreeTurning = false;
           findNearestCP();
           //curvyOn = true;
       } else
       {
           isFreeTurning = true;

           //disable Curvy by removing it's active spline reference
           splineCtrl.Spline = null;
           //curvyOn = false;
       }
   }

   public void findNearestCP()
   {
       //I've already precached all the cp positions in Start() into cpPositions, this LINQ will find the closest one
       var cpClosest = cpPositions.OrderBy(t => (t.transform.position - VRTK_DeviceFinder.PlayAreaTransform().transform.position).sqrMagnitude)
                          .FirstOrDefault();
       Debug.Log("===========" + cpClosest.name);
       Debug.Log(cpClosest.transform.parent.name);

       //follow the closest CP to it's parent so I know what Spline I'm playing with
       CurvySpline parentSpline = cpClosest.transform.parent.GetComponent<CurvySpline>();

       //Insert a new CP before the closest one on the exact player position (this way it forms a path to the "next" one)
       parentSpline.InsertBefore(cpClosest.GetComponent<CurvySplineSegment>(), VRTK_DeviceFinder.PlayAreaTransform().transform.position);

       //Not sure if necessary?
       parentSpline.Refresh();
       Debug.Log("TF:"+ parentSpline.GetNearestPointTF(VRTK_DeviceFinder.PlayAreaTransform().transform.position));

       //put the closest CP's spline onto the controllers active spline
       splineCtrl.Spline = parentSpline;

       //This is my attempt to set the position of the spline to the nearest CP (which should now be the one I "insterBefore" above, ie. right on my player)
       //It was added as an attempt to fix the offsetting, but didn't help
       splineCtrl.Position = parentSpline.GetNearestPointTF(VRTK_DeviceFinder.PlayAreaTransform().transform.position);
       
   }
Reply


Messages In This Thread
RE: Freewalk mode, then return to spline - by mythstified - 08-27-2018, 10:17 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Curvy Line Renderer for UI Spline? gekido 3 6 04-04-2024, 12:56 PM
Last Post: _Aka_
  Get position of all control points for a spline gekido 1 6 03-28-2024, 10:08 PM
Last Post: _Aka_
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
  GO can't fit end of the spline GameDeveloperek4123 3 14 03-04-2024, 11:06 AM
Last Post: _Aka_

Forum Jump: