Exemple #1
0
    public void interpolatedRewind()
    {
        //	This value is pretty important. From this value, we're trying to figure out
        //		a specific value in between the first and second Object State.
        //		Ex. What is the Object State that is 1/5 of the transition between
        //		Object State 1 and Object State 2?

        slowdown = Mathf.Lerp(0, 1, slowdown_t);
        float frameDerivedInterpolation = slowdown;

        if (ObjectStates.Count > 1)
        {
            gameObject.GetComponent <Renderer> ().enabled     = true;
            gameObject.GetComponent <Rigidbody> ().useGravity = false;

            //	lerpInterpolationBetweenTwoStates is a helper function I defined within the
            //		ObjectState class. Feel free to give it a look!
            ObjectState startingState     = ObjectStates [0];
            ObjectState endingState       = ObjectStates [1];
            ObjectState interpolatedState = startingState.lerpInterpolationBetweenTwoStates(endingState, frameDerivedInterpolation);

            transform.position = interpolatedState.position;
            transform.rotation = interpolatedState.rotation;

            slowdown_t += 4f * Time.fixedDeltaTime;


            //	Since we're generating the positions in between two Object States,
            //		we need to make sure that we get rid of old Object States that
            //		we've already used. In other words, after we've generated all
            //		the transitions between Object State 1 and Object State 2, we
            //		need to delete Object State 1 so we don't use it again.

            pruneSampledObjectStatesByTime();
        }
        else
        {
            gameObject.GetComponent <Rigidbody> ().useGravity = true;
            stopRewind();
        }
    }