Rotation assistance.

So I’m having a bit of difficulty with correctly rotating a bone the way I need it.

I have no animations to play with so this is purely Transform based movements.

I’m using FinalIK to position the hands in the positions I want. Simple transform manipulation. I set up a Up, Middle, and Down for each Hand position that looked good. Then I made a yDiff variable which is where the mouse is currently. If its in the middle its 0 if its > 0 its moving up… < 0 its down.

Then based on that mouse position ( +/- 5.9f yAxis) I would move a % from that (Upper|Lower) Transform and the Middle Transform. I figure its because I’m manipulating the Euler Angles directly.

Here is a video of what is happening at certain positions : >>Video<<

 float yDiff = 0;
            yDiff = lookAtTarget.position.y - differenceObject.position.y;
            if (yDiff > 0   LeftHand == HandState.Drawn)
            {
                //Smoothly move to our target position.
                float step = Mathf.Abs((yDiff / 5.9f));
                //Set our position to the upper position mixed with our middle state based on the step.
                _leftHandMovePosition.position = (leftHandLocPistolReady.position * (1 - step)) + (leftHandDrawn_Upper.position * step); 

                //Calculate the rotation for the step we are in.
                Vector3 normalRot = (leftHandLocPistolReady.eulerAngles * (1 - step));
                Vector3 upperRot = (leftHandDrawn_Upper.eulerAngles * step);

                Debug.Log((normalRot + upperRot));
                _leftHandMovePosition.rotation = Quaternion.Euler(normalRot + upperRot);
            }
            
            if (yDiff < 0  LeftHand == HandState.Drawn)
            {
                //Smoothly move to our target position.
                float step = Mathf.Abs((yDiff / -5.9f));
                //Set our position to the lower position mixed with our middle state based on the step.
                _leftHandMovePosition.position = (leftHandLocPistolReady.position * (1 - step)) + (leftHandDrawn_Lower.position * step);

                //Calculate the rotation for the step we are in.
                Vector3 normalRot = (leftHandLocPistolReady.eulerAngles * (1 - step));
                Vector3 lowerRot = (leftHandDrawn_Lower.eulerAngles * step);

                Debug.Log((normalRot + lowerRot));
                _leftHandMovePosition.rotation = Quaternion.Euler(normalRot + lowerRot);

            }
            if (LeftHand == HandState.Drawn  setLookDir)
            {
                //setLookDir = false;
                leftDrawnRevolver.LookAt(lookAtTarget);
                _gunBarrel_Left.LookAt(lookAtTarget);
            }

            _leftHandPosition.position = Vector3.Lerp(_leftHandPosition.position, _leftHandMovePosition.position, Time.deltaTime * drawSpeed);
            _leftHandPosition.rotation = Quaternion.Slerp(_leftHandPosition.rotation, _leftHandMovePosition.rotation, Time.deltaTime * drawSpeed);

So I found the solution that is working for me.

Since I have a “Step” variable (basically the % at which I want that rotation to be) I was able to use Slerp to mix the Rotations the way I was hoping for:

This code snippet I am posting is running in a Update. So the _leftLastStep variable was declared as a private float in the class scope.

  • I’m not showing everything and usually I would update the _leftHandPosition after this logic, which is where the position is being updated. This is still not perfect but its the right direction for me. Unless others have further input

Anyways here is the code:

           float yDiff = 0;
            yDiff = lookAtTarget.position.y - differenceObject.position.y;
            if (yDiff > 0   LeftHand == HandState.Drawn)
            {
                //Smoothly move to our target position.
                float step = Mathf.Abs((yDiff / 5.9f));
                //Set our position to the upper position mixed with our middle state based on the step.
                _leftHandMovePosition.position = (leftHandLocPistolReady.position * (1 - step)) + (leftHandDrawn_Upper.position * step);

                //Calculate the rotation for the step we are in.
                if (_leftLastStep > step || _leftLastStep < step)
                {
                    if (_leftLastStep < step)
                        _leftHandPosition.rotation = Quaternion.Slerp(_leftHandPosition.rotation, leftHandDrawn_Upper.rotation, (step) * drawSpeed * Time.deltaTime);
                    else
                        _leftHandPosition.rotation = Quaternion.Slerp(_leftHandPosition.rotation, _leftHandMovePosition.rotation, (1 - step) * drawSpeed * Time.deltaTime);
                }
                _leftLastStep = step;
            }
            
            if (yDiff < 0  LeftHand == HandState.Drawn)
            {
                //Smoothly move to our target position.
                float step = Mathf.Abs((yDiff / -5.9f));
                //Set our position to the lower position mixed with our middle state based on the step.
                _leftHandMovePosition.position = (leftHandLocPistolReady.position * (1 - step)) + (leftHandDrawn_Lower.position * step);

                //Calculate the rotation for the step we are in.
                if (_leftLastStep > step || _leftLastStep < step)
                {
                    if (_leftLastStep < step)
                        _leftHandPosition.rotation = Quaternion.Slerp(_leftHandPosition.rotation, leftHandDrawn_Lower.rotation, step * drawSpeed * Time.deltaTime);
                    else
                        _leftHandPosition.rotation = Quaternion.Slerp(_leftHandPosition.rotation, _leftHandMovePosition.rotation, (1 - step) * drawSpeed * Time.deltaTime);
                }
                _leftLastStep = step;

            }