Skip to content

cowtrix/zSplines

Repository files navigation

zSplines

Spline library for Unity

RoadNetwork_Pathfinding

Contains two object classes, Spline and SplineSegment. A Spline is a collection of SplineSegments which connect into one continous path.

Create a new spline and draw it as a Gizmos:

zSpline

void OnDrawGizmos()
{
  var spline = new Spline();
  spline.Segments.Add(new SplineSegment // We add a new segment
  {
    FirstControlPoint = new SplineSegment.ControlPoint
    {
      Position = new Vector3(-10, 0, -10),
      Control = new Vector3(10, 0, 0),      // Determines the normal of the spline point
    },
    SecondControlPoint = new SplineSegment.ControlPoint
    {
      Position = new Vector3(10, 0, 10),
      Control = new Vector3(0, 0, -10),
    },
    Resolution = .25f,  // Determines how many points are calculated on the spline path
  });
  spline.Recalculate();
  spline.DrawGizmos(Color.white);
}

Get a point along a spline via distance

zSpline_Point

var distance = 4.5f;
var point = spline.GetDistancePointAlongSpline(distance);

About

Spline library for Unity

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages