question about CharacterIK

zsj

New member
i have two question about characterIK, can someone explain to me?

1. void RotateHands()
Code:
targetRotation =
    // what does it mean ?
    Quaternion.LookRotation(lookDirection, m_CharacterLocomotion.Up) * Quaternion.Inverse(m_Transform.rotation) *
    // then apply spring rotation
    Quaternion.Euler(m_Transform.TransformDirection(i == 0 ? m_LeftHandRotationSpring.Value : m_RightHandRotationSpring.Value)) *
    // first apply animation rotation
    targetRotation;

2. void OnAnimatorIK(int layerIndex)
Code:
        /// <summary>
        /// Update the IK position and weights.
        /// </summary>
        /// <param name="layerIndex">The animator layer that is affected by IK.</param>
        private void OnAnimatorIK(int layerIndex)
        {
            m_CharacterLocomotion.EnableColliderCollisionLayer(false);

            if (layerIndex == m_BaseLayerIndex) { // Base layer.
                // Any target interpolations should first be updated before ik is run.
                UpdateTargetInterpolations();
                // Position the legs to stand on the ground.
                PositionLowerBody();
                // The upper body should look in the direction of the LookSource.
                LookAtTarget();
            } else if (layerIndex == m_UpperBodyLayerIndex) { // Upper body.
                // If the character is aiming the hands should be rotated towards the target.
                RotateHands();
                // The upper arms should look in the direction of the target.
                RotateUpperArms();
                // If the character is aiming the hands should be positioned towards the target.
                PositionHands();
            } else if (m_RequireSecondHandPositioning) { // Full body layer.
                // If an IK target is set the hands need to be positioned again so they match the upper body rotation.
                PositionHands();
            }

            m_CharacterLocomotion.EnableColliderCollisionLayer(true);
        }
RotateUpperArms after RotateHands may change the result of RotateHands, how it works?
 
Quaternion.LookRotation creates a rotation based on the supplied facing and up directions. So that first line uses the character's look direction and up direction.

I'm not sure what your question is about the second method. All of that script is just IK positioning stuff that shouldn't ever need to be modified, so what are you trying to figure out?
 
Quaternion.LookRotation creates a rotation based on the supplied facing and up directions. So that first line uses the character's look direction and up direction.

I'm not sure what your question is about the second method. All of that script is just IK positioning stuff that shouldn't ever need to be modified, so what are you trying to figure out?
I'm learning from this excellent project, not for use for now, so my question looks strange maybe.

I have read the quaternion theory and unity api, but it is still hard to understand exactly what they do.
 
It's definitely pretty complex stuff, I don't understand all of it, but I'm sure continued reading and testing will help - good luck!
 
Top