Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Freewalk mode, then return to spline
#1
I want to offer my users the ability to turn off the guided spline and walk wherever they want.  So they can go off course a bit.  But if they get lost, they can hit a button and I'll find the nearest CP and set a course to that CP.

I've gotten it to kindof work so far.  But something really odd happens.

So my idea was that after I toggle on freewalk mode, it will remove the spline from the player's SplineController.  When I toggle it back on a few things occur.  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.

It actually works!  Except, my player is FOREVER offset from the distance that he veered off course.  I even set the spline controllers relative position to the same one that's generated from the new InsertBefore CP (say, 0.371293) thinking that it might help.  No.  It's weird that creating a CP right on top of my character, and also setting the position to that CP, would jolt my character a few feet off.

Any thoughts on this?  I'm honestly surprised this happens at all... not even sure what method to play with to ensure I can reenable the spline and walk upon it as if nothing changed.
Reply
#2
(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.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#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
#4
Hi,

I tried reproducing your issue but couldn't. Maybe some of your code modifies the OffsetRadius or some other parameters. Anyways, I have attached a working version of your code, with an example scene. I am sure that, by comparing my scene to yours, you will quickly find your issue's cause.

Unrelated to that issue, I have some remarks about your code:
  • Based on your comment, cpPositions is build at Start. Just make sure that if the spline updates, you update that list too. In my code I used spline.ControlPointsList directly.
  • You will have a better result if you have some logic to decide whether to use InsertBefore or InsertAfter, depending on your level configuration.
  • InsertBefore does by default refresh the spline, no need to call the Refresh afterwards.


Attached Files
.zip   FreeWalkTest.zip (Size: 5.31 KB / Downloads: 1)
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#5
(08-28-2018, 01:48 PM)_Aka_ Wrote: Hi,

I tried reproducing your issue but couldn't. Maybe some of your code modifies the OffsetRadius or some other parameters. Anyways, I have attached a working version of your code, with an example scene. I am sure that, by comparing my scene to yours, you will quickly find your issue's cause.

Unrelated to that issue, I have some remarks about your code:
  • Based on your comment, cpPositions is build at Start. Just make sure that if the spline updates, you update that list too. In my code I used spline.ControlPointsList directly.
  • You will have a better result if you have some logic to decide whether to use InsertBefore or InsertAfter, depending on your level configuration.
  • InsertBefore does by default refresh the spline, no need to call the Refresh afterwards.

Thanks for doing that for me.  It helped me determine that there was something else going on.  Out of the corner of my eye I noticed that the player which had the controller object *WAS* moving to the spline, but the VRTK "playareatransform" was NOT.  Changing this reference to the Player position instead seems to make it right!  

By the way, the reason why I build cpPositions at the start is because my map will have MANY splines with connections linking them together.  If my player wanders too far away from the old spline and is now closer to another spline, it'll hook to that one.

So far it's working good, even added some more code to delete the "temporary" control point.  Thanks for the help!
Reply
#6
You are welcome. I am curious to see your game once it is ready to be shown to the public.
Have a nice day.
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.
Reply
#7
(08-28-2018, 11:35 PM)mythstified Wrote:
(08-28-2018, 01:48 PM)_Aka_ Wrote: Hi,

I tried reproducing your issue but couldn't. Maybe some of your code modifies the OffsetRadius or some other parameters. Anyways, I have attached a working version of your code, with an example scene. I am sure that, by comparing my scene to yours, you will quickly find your issue's cause.

Unrelated to that issue, I have some remarks about your code:
  • Based on your comment, cpPositions is build at Start. Just make sure that if the spline updates, you update that list too. In my code I used spline.ControlPointsList directly.
  • You will have a better result if you have some logic to decide whether to use InsertBefore or InsertAfter, depending on your level configuration.
  • InsertBefore does by default refresh the spline, no need to call the Refresh afterwards.

Thanks for doing that for me.  It helped me determine that there was something else going on.  Out of the corner of my eye I noticed that the player which had the controller object *WAS* moving to the spline, but the VRTK "playareatransform" was NOT.  Changing this reference to the Player position instead seems to make it right!  

By the way, the reason why I build cpPositions at the start is because my map will have MANY splines with connections linking them together.  If my player wanders too far away from the old spline and is now closer to another spline, it'll hook to that one.

So far it's working good, even added some more code to delete the "temporary" control point.  Thanks for the help!

Its totally based on that mode you can change it whenever you like it (Y)
Reply


Possibly Related Threads...
Thread Author Replies Views Last Post
  Rotation issue on a Parented Spline Controller Karthik7Nike 6 157 12-07-2018, 09:35 AM
Last Post: _Aka_
  Generated meshes not 'parallel' to spline Alexey 8 316 11-20-2018, 07:13 PM
Last Post: Alexey
  Creating a threaded pole along a spline? spedepasanen 1 308 08-14-2018, 12:25 PM
Last Post: _Aka_
  Generate Spline and Segments dynamically with a script?? mythstified 3 482 08-10-2018, 12:43 PM
Last Post: _Aka_

Forum Jump: