Unity 2019.2.17f1MIT LicenseUpdated 8 days agoCreated on August 19th, 2015
Go to source

# NaughtyBezierCurves

NaughtyBezierCurves is an extension for Unity that provides a BezierCurve GameObject.   ## System Requirements

Unity 2017.3.0 or later versions.

## Installation

``````"com.dbrizov.naughtybeziercurves": "https://github.com/dbrizov/NaughtyBezierCurves.git#upm"
``````

## Features

• Curve modification directly in the Scene View via Key Points with Handles
• Custom editor for Adding, Deleting and Reordering Key Points very easily
• Full Undo/Redo integration

## Ways to create a BezierCurve GameObject

• From the Top Menu -> GameObjects -> Create Other -> Bezier Curve
• Right click in the Hierarchy View -> Create Other -> Bezier Curve
• Drag the prefab in the Scene (The prefab is located in “Assets/Bezier Curves/Prefabs” folder)

## Code Examples

``````BezierCurve3D curve = GetComponent<BezierCurve3D>();

// Evaluate a position and rotation along the curve at a given time
float time = 0.5f; // In range [0, 1]
Vector3 position = curve.GetPoint(time);
Quaterion rotation = curve.GetRotation(time, Vector3.up);

// Get the length of the curve
// This operation is not very heavy, but I advise you to cache the length if you are going to use it
// many times and when you know that the curve won't change at runtime.
float length = curve.GetApproximateLength();

// Other methods
Vector3 tangent = curve.GetTangent(time);
Vector3 binormal = curve.GetBinormal(time, Vector3.up);
Vector3 normal = curve.GetNormal(time, Vector3.up);

// Add a key point at the end of the curve
BezierPoint3D keyPoint = curve.AddKeyPoint(); // via fast method
BezierPoint3D keyPoint = curve.AddKeyPointAt(curve.KeyPointsCount); // via specific index

// Remove a key point
bool isRemoved = curve.RemoveKeyPointAt(0); // Remove the first key point

// Foreach all key points
for (int i = 0; i < curve.KeyPointsCount; i++)
{
Debug.Log(curve.KeyPoints[i].Position);
Debug.Log(curve.KeyPoints[i].LeftHandleLocalPosition);
Debug.Log(curve.KeyPoints[i].RightHandleLocalPosition);
}
``````