Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.

Resolved [Splines] How to determine/evaluate if a knot has been passed/reached?

Discussion in 'World Building' started by ManuelRauber, Jan 8, 2023.

  1. ManuelRauber

    ManuelRauber

    Joined:
    Apr 3, 2015
    Posts:
    114
    Hi!

    I'm currently fiddling around with the Unity Splines package.

    At runtime, the player can click + drag to dynamically create a spline that an object will follow. I also use Spline Extrude to make the spline visible.

    Now, I want that as soon as the object "hits" or "passes" a knot that the passed knot is removed.

    However, I have a hard time figuring out when a knot has been passed. I'm simply using Spline.Evaluate to get the position and tangent which works well.

    Any idea how I can achieve this?

    Thanks!
     
  2. kaarrrllll

    kaarrrllll

    Unity Technologies

    Joined:
    Aug 24, 2017
    Posts:
    548
    You can use
    Code (CSharp):
    1. public static float ConvertIndexUnit<T>(this T spline, float t, PathIndexUnit targetPathUnit)
    2.     where T : ISpline
    3.  
    to convert from a normalized interpolation ratio to PathIndexUnit.Knot. The knot index will be the integer part of the returned value.
     
  3. ManuelRauber

    ManuelRauber

    Joined:
    Apr 3, 2015
    Posts:
    114
    This is exactly what I was looking for. Thanks @kaarrrllll :)
     
    GDevTeam and kaarrrllll like this.
  4. Ziplaw

    Ziplaw

    Joined:
    Sep 24, 2018
    Posts:
    4
    Now how would I do the reverse? What if I want to convert from Knot to normalized distance?, Better yet, how would I get the normalized position of a Knot in a given Spline
     
  5. ManuelRauber

    ManuelRauber

    Joined:
    Apr 3, 2015
    Posts:
    114
    Please open your own thread, instead of hijacking a resolved one. :)