Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
how do I position a splineController on a spline in runtime to an exact position?
#1
Code:
mySplineController.Position = 0.5f;
or
Code:
mySplineController.Position = myPath.Length*0.5f
doesn't really seem to do anything, the spline controller just starts at the start of the spline.

What's the best way to tell a spline controller to explicitly go to a position along a spline?

I tried turning Play Automatically on and off but that stop speed from moving the spline controller.
Reply
#2
My guess is that you are giving a relative distance while your controller expects an absolute one.
Position sets/gets either the absolute or relative position (TF) depending on your controller's MoveMode.
So either set that mode to Relative, or use mySplineController.RelativePosition, which always takes a relative position, regardless of the controller's MoveMode.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#3
(01-16-2018, 09:07 PM)_Aka_ Wrote: My guess is that you are giving a relative distance while your controller expects an absolute one.
Position sets/gets either the absolute or relative position (TF) depending on your controller's MoveMode.
So either set that mode to Relative, or use mySplineController.RelativePosition, which always takes a relative position, regardless of the controller's MoveMode.

Hello, Aka

I actually came here with the same question. I have my spline in relative mode, and I am setting Position based on that expectation (values ranging from 0.0f to 1.0f inclusive). The SplineController doesn't move for me. Is there another method I need to call? Special values needed in the other Inspector settings for this SplineController? I suspect my script-driven setting is fighting with the SplineController's own built-in calculation, although I have turned off the option to automatically play the motion.
Reply
#4
Hi,
Did you use RelativePosition instead of Position? If yes, what was the result?
And when you say "my spline is in relative mode", do you mean Position Mode is relative, or Move Mode is relative?
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#5
(01-17-2018, 11:06 PM)_Aka_ Wrote: Hi,
Did you use RelativePosition instead of Position? If yes, what was the result?
And when you say "my spline is in relative mode", do you mean Position Mode is relative, or Move Mode is relative?

I had move mode in absolute units when I was testing with the built-in movement, because that made the speed setting more intuitive. I discovered (as you probably were about to tell me...) that I needed this in Relative mode if I was going to set it from a script. Oops.

So the prerequisites seem to be that Position Mode and Movement Mode should be the same as what my C# script expects. I also found it needs to be in Play mode to do the updates. Again, you probably knew this already. Smile

We can consider this solved. It's working now. Thanks!
Reply
#6
Thanks I changed to a relative position and went from there, works nicely however in the end I had to make it a coroutine and do a while loop to make it / force it to go to the place I wanted, seems sometimes spline controllers go to 0... took about 5~10 frames before it went to the correct position. heres the code:

Code:
    IEnumerator PlaceOnOpenTrack()
    {
        mySC.Spline = myPath;
        float desiredPos = path1.Length + (path2.Length * 0.5f);
        mySC.Position = desiredPos;
        if (mySC.Position == 0)
        {
            while( mySC.Position == 0 )
            {
                // Debug.Log(mySC.Position);
                mySC.Position = desiredPos;
                yield return null;
            }
        }
    }
Reply
#7
(01-18-2018, 04:19 AM)hawken Wrote: Thanks I changed to a relative position and went from there, works nicely however in the end I had to make it a coroutine and do a while loop to make it / force it to go to the place I wanted, seems sometimes spline controllers go to 0... took about 5~10 frames before it went to the correct position.


This seems overly complicated.
Here is a simple way to do the switch:
Code:
if (splineController.Spline == Spline1)
    splineController.Spline = Spline2;
else
    splineController.Spline = Spline1;

splineController.RelativePosition = 0.5f;

//Uncomment this if your splineController has PlayAutomatically set to false
//splineController.Play();

I also attached a scene with this code in a script. You just have to click or press any button in playmode to operate the switch


Attached Files
.zip   InstantSwitcher.zip (Size: 10.18 KB / Downloads: 4)
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply
#8
(01-18-2018, 02:41 PM)_Aka_ Wrote:
(01-18-2018, 04:19 AM)hawken Wrote: Thanks I changed to a relative position and went from there, works nicely however in the end I had to make it a coroutine and do a while loop to make it / force it to go to the place I wanted, seems sometimes spline controllers go to 0... took about 5~10 frames before it went to the correct position.


This seems overly complicated.
Here is a simple way to do the switch:
Code:
if (splineController.Spline == Spline1)
    splineController.Spline = Spline2;
else
    splineController.Spline = Spline1;

splineController.RelativePosition = 0.5f;

//Uncomment this if your splineController has PlayAutomatically set to false
//splineController.Play();

I also attached a scene with this code in a script. You just have to click or press any button in playmode to operate the switch

thanks for this, I'm generating "myPath" in run time from 3 other paths, I wait until it's initialised then run that script. It works fine the first time I make my SC jump to it, but for some reason if I repeat the process it always defaults to position 0 for a few frames then by brute force I keep trying to move it to the requested position. I'm guessing the new spline that is generated isn't initialised.
Reply
#9
Hmm, initialization shouldn't take more than one frame, so maybe your issue comes from something else. If you send me the actual scene and scripts you use, I will try to find where the issue come from.
Please consider leaving a review for Curvy, this helps immensely. Thank you.
Available for freelance work—feel free to reach out.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Method of scattering objects along spline joebain 1 3 11-26-2024, 03:20 PM
Last Post: _Aka_
  Curvy Line Renderer for UI Spline? gekido 5 13 10-29-2024, 10:19 AM
Last Post: _Aka_
  Nested Spline Volume Spot Instantiation merobbins5 3 7 07-26-2024, 09:58 AM
Last Post: _Aka_
  Left-right movement, and spline follow shihaya 3 10 07-12-2024, 12:50 PM
Last Post: _Aka_

Forum Jump: