//EXPERIMENTAL //called on every tween update for lerping rotation between waypoints private void OnWaypointRotation() { int lookPoint = currentPoint; lookPoint = Mathf.Clamp(pathContainer.GetWaypointIndex(currentPoint), 0, pathContainer.GetWaypointCount()); if (!tween.IsInitialized() || tween.IsComplete()) { ApplyWaypointRotation(pathContainer.GetWaypoint(lookPoint).rotation); return; } TweenerCore <Vector3, Path, PathOptions> tweenPath = tween as TweenerCore <Vector3, Path, PathOptions>; float currentDist = tweenPath.PathLength() * tweenPath.ElapsedPercentage(); float pathLength = 0f; float currentPerc = 0f; int targetPoint = currentPoint; if (moveToPath) { pathLength = tweenPath.changeValue.wpLengths[1]; currentPerc = currentDist / pathLength; ApplyWaypointRotation(Quaternion.Lerp(originRot, pathContainer.GetWaypoint(currentPoint).rotation, currentPerc)); return; } if (pathContainer is BezierPathManager) { BezierPathManager bPath = pathContainer as BezierPathManager; int curPoint = currentPoint; if (reverse) { targetPoint = bPath.GetWaypointCount() - 2 - (waypoints.Length - currentPoint - 1); curPoint = (bPath.bPoints.Count - 2) - targetPoint; } int prevPoints = (int)(curPoint * bPath.pathDetail * 10); if (bPath.customDetail) { prevPoints = 0; for (int i = 0; i < targetPoint; i++) { prevPoints += (int)(bPath.segmentDetail[i] * 10); } } if (reverse) { for (int i = 0; i <= curPoint * 10; i++) { currentDist -= tweenPath.changeValue.wpLengths[i]; } } else { for (int i = 0; i <= prevPoints; i++) { currentDist -= tweenPath.changeValue.wpLengths[i]; } } if (bPath.customDetail) { for (int i = prevPoints + 1; i <= prevPoints + bPath.segmentDetail[currentPoint] * 10; i++) { pathLength += tweenPath.changeValue.wpLengths[i]; } } else { for (int i = prevPoints + 1; i <= prevPoints + 10; i++) { pathLength += tweenPath.changeValue.wpLengths[i]; } } } else { if (reverse) { targetPoint = waypoints.Length - currentPoint - 1; } for (int i = 0; i <= targetPoint; i++) { currentDist -= tweenPath.changeValue.wpLengths[i]; } pathLength = tweenPath.changeValue.wpLengths[targetPoint + 1]; } currentPerc = currentDist / pathLength; if (pathContainer is BezierPathManager) { lookPoint = targetPoint; if (reverse) { lookPoint++; } } currentPerc = Mathf.Clamp01(currentPerc); ApplyWaypointRotation(Quaternion.Lerp(pathContainer.GetWaypoint(lookPoint).rotation, pathContainer.GetWaypoint(reverse ? lookPoint - 1 : lookPoint + 1).rotation, currentPerc)); }
//EXPERIMENTAL //called on every tween update for lerping rotation between waypoints private void OnWaypointRotation() { int lookPoint = currentPoint; lookPoint = Mathf.Clamp(pathContainer.GetWaypointIndex(currentPoint), 0, pathContainer.GetWaypointCount()); if (!tween.IsInitialized() || tween.IsComplete()) { ApplyWaypointRotation(pathContainer.GetWaypoint(lookPoint).rotation); return; } TweenerCore <Vector3, Path, PathOptions> tweenPath = tween as TweenerCore <Vector3, Path, PathOptions>; float currentDist = tweenPath.PathLength() * tweenPath.ElapsedPercentage(); float pathLength = 0f; float currentPerc = 0f; int targetPoint = currentPoint; if (moveToPath) { pathLength = tweenPath.changeValue.wpLengths[1]; currentPerc = currentDist / pathLength; ApplyWaypointRotation(Quaternion.Lerp(originRot, pathContainer.GetWaypoint(currentPoint).rotation, currentPerc)); return; } if (pathContainer is BezierPathManager) { BezierPathManager bPath = pathContainer as BezierPathManager; int curPoint = currentPoint; if (reverse) { targetPoint = bPath.GetWaypointCount() - 2 - (waypoints.Length - currentPoint - 1); curPoint = (bPath.bPoints.Count - 2) - targetPoint; } int prevPoints = (int)(curPoint * bPath.pathDetail * 10); if (bPath.customDetail) { prevPoints = 0; for (int i = 0; i < targetPoint; i++) { prevPoints += (int)(bPath.segmentDetail[i] * 10); } } if (reverse) { for (int i = 0; i <= curPoint * 10; i++) { currentDist -= tweenPath.changeValue.wpLengths[i]; } } else { for (int i = 0; i <= prevPoints; i++) { currentDist -= tweenPath.changeValue.wpLengths[i]; } } if (bPath.customDetail) { for (int i = prevPoints + 1; i <= prevPoints + bPath.segmentDetail[currentPoint] * 10; i++) { pathLength += tweenPath.changeValue.wpLengths[i]; } } else { for (int i = prevPoints + 1; i <= prevPoints + 10; i++) { pathLength += tweenPath.changeValue.wpLengths[i]; } } } else { if (reverse) { targetPoint = waypoints.Length - currentPoint - 1; } for (int i = 0; i <= targetPoint; i++) { currentDist -= tweenPath.changeValue.wpLengths[i]; } pathLength = tweenPath.changeValue.wpLengths[targetPoint + 1]; } currentPerc = currentDist / pathLength; if (pathContainer is BezierPathManager) { lookPoint = targetPoint; if (reverse) { lookPoint++; } } currentPerc = Mathf.Clamp01(currentPerc); //ApplyWaypointRotation(Quaternion.Lerp(pathContainer.GetWaypoint(lookPoint).rotation, pathContainer.GetWaypoint(reverse ? lookPoint - 1 : lookPoint + 1).rotation, currentPerc)); Vector3 nextPos = tween.PathGetPoint(tweenPath.ElapsedPercentage() + 0.01f); if (local) { nextPos = pathContainer.transform.TransformPoint(nextPos); } rotationTarget.LookAt(nextPos); Transform tfm = pathContainer.GetWaypoint(reverse ? lookPoint - 1 : lookPoint + 1); Quaternion q = Quaternion.FromToRotation(Vector3.forward, forwardDir); rotationTarget.rotation *= q; //q = Quaternion.Lerp(pathContainer.GetWaypoint(lookPoint).rotation, tfm.rotation, currentPerc); //rotationTarget.rotation = q * rotationTarget.rotation; q = Quaternion.Lerp(pathContainer.GetWaypoint(lookPoint).localRotation, tfm.localRotation, currentPerc); rotationTarget.localRotation *= q; rotationTarget.Rotate(eulerAngles); }