i have two question about characterIK, can someone explain to me?
1. void RotateHands()
2. void OnAnimatorIK(int layerIndex)
RotateUpperArms after RotateHands may change the result of RotateHands, how it works?
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);
}