You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Digger.Modules.AdvancedOperations.Splines
|
|
|
|
|
|
{
|
|
|
|
|
|
public class BezierCurve : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
public Vector3[] points;
|
|
|
|
|
|
|
|
|
|
|
|
public void Reset()
|
|
|
|
|
|
{
|
|
|
|
|
|
points = new[]
|
|
|
|
|
|
{
|
|
|
|
|
|
new Vector3(1f, 0f, 0f),
|
|
|
|
|
|
new Vector3(2f, 0f, 0f),
|
|
|
|
|
|
new Vector3(3f, 0f, 0f),
|
|
|
|
|
|
new Vector3(4f, 0f, 0f)
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Vector3 GetPoint(float t)
|
|
|
|
|
|
{
|
|
|
|
|
|
return transform.TransformPoint(Bezier.GetPoint(points[0], points[1], points[2], points[3], t));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Vector3 GetVelocity(float t)
|
|
|
|
|
|
{
|
|
|
|
|
|
return transform.TransformPoint(Bezier.GetFirstDerivative(points[0], points[1], points[2], points[3], t)) - transform.position;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Vector3 GetDirection(float t)
|
|
|
|
|
|
{
|
|
|
|
|
|
return GetVelocity(t).normalized;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|