Example #1
0
        //Start playing IK (Sequence)
        public void StartSequence(int id, IKType goal, List <IKSequence> iKSequence, bool smoothEntry, bool isLoop)
        {
            if (!CheckAvailability(id))
            {
                return;
            }

            StateIK state = stateIKs[id];

            state.activeAttachment = 0;
            state.iKGoal           = goal;

            if (smoothEntry)
            {
                state.IKs[0].weight = 0;
            }
            else
            {
                state.IKs[0].weight = 1;
            }

            StopIK(id);
            state.isActive       = true;
            state.stateCoroutine = PerformSequence(id, iKSequence, smoothEntry, isLoop, 0);
            StartCoroutine(state.stateCoroutine);
        }
Example #2
0
        //Perform smooth state IK change (Single)
        IEnumerator SmoothStateIKChange(StateIK nextState, StateIK previousState, float speed, IKType goal)
        {
            previousState.IKs[0].iKAttachment.localPosition = previousState.IKs[0].initPos;
            previousState.IKs[0].iKAttachment.localRotation = previousState.IKs[0].initRot;

            previousState.IKs[0].weight = 1;

            Vector3    endPos = nextState.IKs[0].iKAttachment.localPosition;
            Quaternion endRot = nextState.IKs[0].iKAttachment.localRotation;
            float      i      = 0;

            while (i < 1)
            {
                i += Time.deltaTime / speed;
                previousState.IKs[0].iKAttachment.localPosition = Vector3.Lerp(previousState.IKs[0].initPos, endPos, i);
                previousState.IKs[0].iKAttachment.localRotation = Quaternion.Lerp(previousState.IKs[0].initRot, endRot, i);
                yield return(0);
            }

            playing = true;

            nextState.isActive         = true;
            nextState.activeAttachment = 0;
            nextState.iKGoal           = goal;
            nextState.IKs[0].weight    = 1;

            previousState.isActive = false;

            previousState.IKs[0].iKAttachment.localPosition = previousState.IKs[0].initPos;
            previousState.IKs[0].iKAttachment.localRotation = previousState.IKs[0].initRot;
        }
Example #3
0
        ///IK FUNCTIONS
        //Start playing IK (Single)
        public void StartSingleIK(int id, IKType goal, bool smooth, float speed)
        {
            if (!CheckAvailability(id))
            {
                return;
            }

            if (stateIKs[id].isActive)
            {
                return;
            }

            StateIK state = null;



            if (previousIK[(int)goal] > -1 && previousIK[(int)goal] != id)
            {            //Used when switching between IK States
                if (smooth)
                {
                    state = stateIKs[previousIK[(int)goal]];

                    StopIK(previousIK[(int)goal]);
                    previousIK[(int)goal] = id;
                    state.stateCoroutine  = SmoothStateIKChange(stateIKs[id], state, speed, goal);
                    StartCoroutine(state.stateCoroutine);
                }
            }
            else
            {
                //Used by default

                previousIK[(int)goal] = id;

                state                  = stateIKs[id];
                state.isActive         = true;
                state.activeAttachment = 0;
                state.iKGoal           = goal;

                if (smooth)
                {
                    state.IKs[0].weight = 0;
                }
                else
                {
                    state.IKs[0].weight = 1;
                }

                StopIK(id);
                state.stateCoroutine = PerformSingleIK(id, state.IKs[state.activeAttachment], 0, smooth, speed);
                StartCoroutine(state.stateCoroutine);
            }
        }