-
-
Save robert-michels/f5dc0de4f8c45b8b3bbd7080885e684e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // CODE SNIPPET, NOT THE FULL FILE // | |
| void Update() | |
| { | |
| //Don't move | |
| if (mState == "Reset" || mState == "Stopped" || mNodes.Count < 4) return; | |
| /////////////////////// Control movement along path /////////////////////////// | |
| MonitorInput(); | |
| if (!paused) mCurrentTime += Time.deltaTime; | |
| // We advance to next point in the path | |
| if (mCurrentTime >= mNodes[mCurrentIdx + 1].Time) | |
| { | |
| if (mCurrentIdx < mNodes.Count - 3) | |
| { | |
| mCurrentIdx++; | |
| } | |
| else | |
| { | |
| if (mState != "Loop") | |
| { | |
| mState = "Stopped"; | |
| // We stop right in the end point | |
| transform.position = mNodes[mNodes.Count - 2].Point; | |
| if (mRotations) | |
| transform.rotation = mNodes[mNodes.Count - 2].Rot; | |
| // We call back to inform that we are ended | |
| if (mOnEndCallback != null) | |
| mOnEndCallback(); | |
| } | |
| else | |
| { | |
| mCurrentIdx = 1; | |
| mCurrentTime = 0; | |
| } | |
| } | |
| } | |
| // We are in motion -> Interpolate position and orientation along path | |
| if (mState != "Stopped") | |
| { | |
| // Calculates the t param between 0 and 1 | |
| float param = (mCurrentTime - mNodes[mCurrentIdx].Time) / (mNodes[mCurrentIdx + 1].Time - mNodes[mCurrentIdx].Time); | |
| // Smooth the param | |
| param = MathUtils.Ease(param, mNodes[mCurrentIdx].EaseIO.x, mNodes[mCurrentIdx].EaseIO.y); | |
| transform.position = GetHermiteInternal(mCurrentIdx, param); | |
| if (mRotations) | |
| { | |
| transform.rotation = GetSquad(mCurrentIdx, param); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment