Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
To dynamic generate the connection between paths
#4
(08-07-2020, 02:47 PM)_Aka_ Wrote: Hi,
  1. Here is an example of code, as seen in the example scene 05_NearestPoint, to get the nearest point on a spline:
    float nearestTF = Spline.GetNearestPointTF(Lookup.position, Space.World);
    transform.position = Spline.Interpolate(nearestTF, Space.World);
    If you want the position of a sample point, in opposition of an exacte position on the spline, use InterpolateFast instead of Interpolate.
  2. You can use the HandleOutPosition and HandleInPosition to set the handles in world coordinates.
  3. I have a GetNearestPointTF that works for rays, but it is not optimized nor properly tested. I attached the needed files to this post. Might nor compile with the latest version of Curvy. If so, fixing the compiler errors should not be difficult.
  4. Not sure about what you mean in your point 4. By creating a spline Curvy aytomatically generates tangents, so you don't have to do it yourself.
  5. If you use SplineController, then you can use the SwitchTo method, or get inspiration from its implementation, to switch between two splines.
Was everything clear?

thanks for quick reply Heart , I miss the "Interpolate" API, that's what I need for tangent info.
(3) was a cool stuff, I'm sure it will be handy
well, forget about (4) you already answer my question on (1) & (2)
btw, (5) "SwitchTo" method looks like it was the feature I wanted to implement, will try to use that method first.

Still cleaning up my code and prepare to migrate into curvy, but based on your answer write following shadow code,
just to make sure I didn't misunderstand anything.

Code:
Transform m_Ship = null; // assume we got this
CurvySpline curveA = null; // assume we got this
CurvySpline curveB = null; // assume we got this

// point on travel path.
float startTF = curveA.GetNearestPointTF(m_Ship.position, Space.World);
curveA.InterpolateAndGetTangentFast(startTF, out Vector3 startPoint, out Vector3 startTangent, Space.World);

// point to switch path.
float endTF = curveB.GetNearestPointTF(startTangent, Space.World);
curveB.InterpolateAndGetTangentFast(endTF, out Vector3 endPoint, out Vector3 endTangent, Space.World);

// Generate path !
var curve = CurvySpline.Create();
var start = curve.Add(startPoint, Space.World);
var end = curve.Add(endPoint, Space.World);
// define tangent(s) from start to end.
start.HandleOutPosition = startTangent;
end.HandleInPosition = endTangent;
Reply


Messages In This Thread
RE: To dynamic generate the connection between paths - by Canis - 08-07-2020, 07:24 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
Bug Changing spline connection in inspector causes splines to revert to defaults lacota 3 6 03-18-2024, 07:55 PM
Last Post: _Aka_
Thumbs Up Can't delete connection lacota 3 6 03-16-2024, 11:34 AM
Last Post: _Aka_
  Cant Generate Meshes At Runtime alms94 5 22 01-26-2024, 11:27 AM
Last Post: _Aka_
Lightbulb Junction & Connection Navigation System Design SAMYTHEBIGJUICY 4 13 11-27-2023, 01:04 PM
Last Post: _Aka_

Forum Jump: