14 [Tooltip(
"position to orbit around")]
15 public Vector3 CenterPoint =
new Vector3();
17 [Tooltip(
"Axis to orbit around")]
18 public Vector3 Axis = Vector3.forward;
20 [Tooltip(
"size of the orbit")]
21 public float Radius = 0.2f;
23 [Tooltip(
"orbit speed")]
24 public float RevolutionSpeed = 2.0f;
26 [Tooltip(
"starting position based on 360 degrees")]
27 public float StartAngle = 0;
29 [Tooltip(
"Limit the amount or revolutions, set to zero for infinite")]
30 public float Revolutions = 0;
32 [Tooltip(
"Orbit the other way")]
33 public bool Reversed =
false;
35 [Tooltip(
"Start automatically")]
36 public bool AutoPlay =
true;
38 [Tooltip(
"pause the orbit or status")]
39 public bool IsPaused =
false;
44 public int RevolutionCount {
get;
private set; }
46 [Tooltip(
"Smooth in and out of the orbit")]
47 public bool SmoothEaseInOut =
false;
49 [Tooltip(
"Smoothness factor")]
50 public float SmoothRatio = 1;
53 private float mAngle = 0;
56 private float mTime = 0;
59 private Vector3 mPositionVector;
62 private Vector3 mRotatedPositionVector;
70 mPositionVector = transform.up;
73 if (!Mathf.Approximately(Vector3.Angle(Axis, mPositionVector), 90))
76 mPositionVector = transform.forward;
77 if (!Mathf.Approximately(Vector3.Angle(Axis, mPositionVector), 90))
79 float x = Mathf.Abs(Axis.x);
80 float y = Mathf.Abs(Axis.y);
81 float z = Mathf.Abs(Axis.z);
86 mPositionVector = Vector3.Cross(Axis * Radius, Vector3.forward);
92 mPositionVector = Vector3.Cross(Axis * Radius, Vector3.right);
98 mPositionVector = Vector3.Cross(Axis * Radius, Vector3.right);
104 transform.Rotate(Axis, mAngle - StartAngle);
105 mRotatedPositionVector = Quaternion.AngleAxis(mAngle - StartAngle, Axis) * mPositionVector * Radius;
106 transform.localPosition = CenterPoint + mRotatedPositionVector;
108 IsPaused = !AutoPlay;
133 return e / 2 * v * v * v * v + s;
135 return -e / 2 * ((v -= 2) * v * v * v - 2) + s;
139 private void Update()
141 if (IsPaused)
return;
144 float percentage = mTime / RevolutionSpeed;
150 float linearSmoothing = 1 * (percentage * (1 - SmoothRatio));
151 percentage = QuartEaseInOut(0, 1, percentage) * SmoothRatio + linearSmoothing;
155 mAngle = 0 - (percentage) * 360;
164 transform.Rotate(Axis, mAngle - StartAngle);
165 mRotatedPositionVector = Quaternion.AngleAxis(mAngle - StartAngle, Axis) * mPositionVector * Radius;
166 transform.localPosition = CenterPoint + mRotatedPositionVector;
169 mTime += Time.deltaTime;
170 if (mTime >= RevolutionSpeed)
172 mTime = RevolutionSpeed - mTime;
173 RevolutionCount += 1;
175 if (RevolutionCount >= Revolutions && Revolutions > 0)