Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SplineController Reset to initial Position
#1
I am using the Spline Controller to move an object along a single spline.

Sometimes I need to "reset" the object to the start of the spline. How do I do that?

I tried calling 
mysplineController.Stop();
mysplineController.Play(); 

but that didn't seem to work so then I did

mysplineController.ResetOnStop = true;
mysplineController.Stop();
mysplineController.Play();

But that causes an exception below.

I also tried mysplineController.Warp(0); 

What is the best way to reset the object to the start of the spline?



Thanks
Jim



IndexOutOfRangeException: Array index is out of range.
FluffyUnderware.Curvy.CurvySplineSegment.DistanceToLocalF (Single localDistance) (at Assets/Packages/Curvy/Base/CurvySplineSegment.cs:2040)
FluffyUnderware.Curvy.CurvySpline.DistanceToTF (Single distance, CurvyClamping clamping) (at Assets/Packages/Curvy/Base/CurvySpline.cs:1100)
FluffyUnderware.Curvy.CurvySplineBase.DistanceToTF (Single distance) (at Assets/Packages/Curvy/Base/CurvySplineBase.cs:411)
FluffyUnderware.Curvy.CurvySplineBase.MoveByLengthFast (System.Single& tf, System.Int32& direction, Single distance, CurvyClamping clamping) (at Assets/Packages/Curvy/Base/CurvySplineBase.cs:724)
FluffyUnderware.Curvy.CurvySpline.MoveByLengthFast (System.Single& tf, System.Int32& direction, Single distance, CurvyClamping clamping) (at Assets/Packages/Curvy/Base/CurvySpline.cs:1184)
FluffyUnderware.Curvy.Controllers.SplineController.Advance (System.Single& tf, System.Int32& direction, MoveModeEnum mode, Single absSpeed, CurvyClamping clamping) (at Assets/Packages/Curvy/Controllers/SplineController.cs:443)
FluffyUnderware.Curvy.CurvyController.Refresh () (at Assets/Packages/Curvy/Base/CurvyController.cs:842)
FluffyUnderware.Curvy.Controllers.SplineController.Refresh () (at Assets/Packages/Curvy/Controllers/SplineController.cs:258)
FluffyUnderware.Curvy.CurvyController.Update () (at Assets/Packages/Curvy/Base/CurvyController.cs:609)
Reply
#2
Either use 

mySplineController.Reset()  

or 

mySplineController.Position=mySplineController.InitialPosition

Both should work. I'm looking into the exception, that shouldn't happen. Anyways, ResetOnStop only has an effect if you use the Animate feature.
Reply
#3
Thanks for the fast response 

mySplineController.Reset()   is protected.

Something to note is I am dynamically changing the location of the ControlPoints of the Spline used by the SplineController. So its possible that is part of the cause of the index out of bounds, I suspect the spline is getting shorter and that isnt handled by that code.

Is there something that should be called when the spline is changed?



(06-14-2016, 02:13 PM)Jake Wrote: Either use 

mySplineController.Reset()  

or 

mySplineController.Position=mySplineController.InitialPosition

Both should work. I'm looking into the exception, that shouldn't happen. Anyways, ResetOnStop only has an effect if you use the Animate feature.
Reply
#4
(06-14-2016, 02:59 PM)aspartamed Wrote: Is there something that should be called when the spline is changed?
Yeah, call CurvySpline.Refresh() to immediately use the changes, otherwise Refresh() will be called internally next frame. In general, calling Refresh() often isn't bad - it won't do anything unless spline parts are flagged dirty or you force refresh by Refresh(true).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Avoiding runtime GC allocations on control point position change Ell223 8 18 02-24-2024, 10:43 AM
Last Post: _Aka_
  How could I get position in spline from "From" value in BuildRasterizedPath? Chanon 1 8 02-12-2024, 09:54 PM
Last Post: _Aka_
  Finding relative position across connected splines DekoGames 1 8 02-05-2024, 10:11 PM
Last Post: _Aka_
  Getting object on spline Position when Spline has coordinates larger than 2000 velikizlivuk 5 10 09-05-2023, 01:01 PM
Last Post: velikizlivuk

Forum Jump: