You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

26 lines
664 B

5 years ago
  1. using UnityEngine;
  2. public class BezierCurve : MonoBehaviour {
  3. public Vector3[] points;
  4. public Vector3 GetPoint (float t) {
  5. return transform.TransformPoint(Bezier.GetPoint(points[0], points[1], points[2], points[3], t));
  6. }
  7. public Vector3 GetVelocity (float t) {
  8. return transform.TransformPoint(Bezier.GetFirstDerivative(points[0], points[1], points[2], points[3], t)) - transform.position;
  9. }
  10. public Vector3 GetDirection (float t) {
  11. return GetVelocity(t).normalized;
  12. }
  13. public void Reset () {
  14. points = new Vector3[] {
  15. new Vector3(1f, 0f, 0f),
  16. new Vector3(2f, 0f, 0f),
  17. new Vector3(3f, 0f, 0f),
  18. new Vector3(4f, 0f, 0f)
  19. };
  20. }
  21. }