Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Root Motion on Spline
Good Afternoon, I'm currently trying to "constrain" my character to a spline, Setting its rotation with
 Vector3 P;                                       
    float carTf = path.GetNearestPointTF(transform.position, out P, Space.World); 
    Quaternion splineOrientation = path.GetOrientationFast(carTf);
    float splineOrientationYaw = splineOrientation.eulerAngles.y;
    transform.eulerAngles = new Vector3(0f, splineOrientationYaw, 0f);

this is going well for the rotation part, although for the movement along the spline, I'm trying to get a normalize length of the spline (0 to 1) depending on the current position of my character, is there a simple way to get this value? 

This is for stopping the player when he gets near the end or beginning of the spline.

Thank you and have a good day, excellent profuct by the way!
Thank you for the compliment, always makes me happy to read them Smile
I think this is what you are looking for (possible typos)
var normalizedLength = spline.TfToDistance(carTf) / spline.Length;
Did it work?
Have a nice day

PS: being a French speaker, I found your nickname very funny, then I searched it on the internet. Thanks for making me discover what a puddingchomeur is Big Grin
Please consider leaving a review for Curvy. This will help a lot keeping Curvy relevant in the eyes of the Asset Store algorithm.

Possibly Related Threads…
Thread Author Replies Views Last Post
  Keeping a fixed spline length jh092 3 14 02-21-2024, 06:25 AM
Last Post: Primrose44
  GO can't fit end of the spline GameDeveloperek4123 1 4 02-13-2024, 10:18 AM
Last Post: _Aka_
  How could I get position in spline from "From" value in BuildRasterizedPath? Chanon 1 6 02-12-2024, 09:54 PM
Last Post: _Aka_
  Add noise to spline controller movement DekoGames 2 8 02-06-2024, 01:28 PM
Last Post: DekoGames

Forum Jump: