public void DrawCurve() { if (activated && ControlPoints.Where(point => point == null).Count() == 0) { for (int i = 1; i <= SEGMENT_COUNT; i++) { float t = i / (float)SEGMENT_COUNT; int nodeIndex = 0; Vector3 pixel = BezierMaths.Bezier3(ControlPoints[nodeIndex].Value, ControlPoints[nodeIndex + 1].Value, ControlPoints[nodeIndex + 2].Value, t); lineRenderer.positionCount = i; lineRenderer.SetPosition((i - 1), pixel); } } }
public override ATrajectoryState NextPosition(float deltaTime, Vector3 currentPosition, out Vector3?newPosition, out Quaternion?newRotation) { float increment = (speed * deltaTime) / curveLength; float newCompletion = previousCompletion + increment; if (newCompletion <= 1) { newPosition = BezierMaths.Bezier3(controlPoints, newCompletion); newPosition = new Vector3( newPosition.Value.x, currentPosition.y, newPosition.Value.z ); newRotation = Quaternion.Euler(90, 0, 90 + Mathf.Rad2Deg * Mathf.Atan2(CurrentDirection.z, CurrentDirection.x)); previousCompletion = newCompletion; return(this); } else { return(new StraightTrajectoryStrategy(CurrentDirection, speed).NextPosition(deltaTime, currentPosition, out newPosition, out newRotation)); } }