diff --git a/Assets/Scripts/KindRetargeting/CustomRetargetingScript.cs b/Assets/Scripts/KindRetargeting/CustomRetargetingScript.cs index ccccb5c3..73ff56e1 100644 --- a/Assets/Scripts/KindRetargeting/CustomRetargetingScript.cs +++ b/Assets/Scripts/KindRetargeting/CustomRetargetingScript.cs @@ -1164,29 +1164,37 @@ namespace KindRetargeting // 바닥 높이 적용 targetPosition.y += floorHeight; - // 소스 아바타의 로컬 축 기준으로 발 오프셋 적용 + // 발 본의 로컬 좌표계 기준으로 오프셋 적용 // +Z: 앞으로, -Z: 뒤로 // 왼발: +X로 벌리기, -X로 모으기 // 오른발: -X로 벌리기, +X로 모으기 (반대) - Vector3 footOffset = Vector3.zero; + HumanBodyBones footBone = endBone == HumanBodyBones.LeftToes ? + HumanBodyBones.LeftFoot : HumanBodyBones.RightFoot; + Transform foot = sourceAnimator.GetBoneTransform(footBone); - // 앞뒤 오프셋 (소스 아바타 기준 Z축) - footOffset += sourceAnimator.transform.forward * footFrontBackOffset; - - // 안쪽/바깥쪽 오프셋 (소스 아바타 기준 X축) - // footInOutOffset > 0: 벌리기, < 0: 모으기 - if (endBone == HumanBodyBones.LeftToes) + if (foot != null) { - // 왼발: +일 때 왼쪽(+X)으로 벌림, -일 때 오른쪽(-X)으로 모음 - footOffset += sourceAnimator.transform.right * footInOutOffset; - } - else // RightToes - { - // 오른발: +일 때 오른쪽(-X)으로 벌림, -일 때 왼쪽(+X)으로 모음 - footOffset -= sourceAnimator.transform.right * footInOutOffset; - } + // 로컬 오프셋 계산 + Vector3 localOffset = Vector3.zero; - targetPosition += footOffset; + // 앞뒤 오프셋 (로컬 Z축) + localOffset.z = footFrontBackOffset; + + // 안쪽/바깥쪽 오프셋 (로컬 X축) + if (endBone == HumanBodyBones.LeftToes) + { + // 왼발: +X로 벌림 + localOffset.x = footInOutOffset; + } + else // RightToes + { + // 오른발: -X로 벌림 + localOffset.x = -footInOutOffset; + } + + // 로컬 오프셋을 월드 좌표로 변환하여 적용 + targetPosition += foot.TransformDirection(localOffset); + } } // 최종 위치와 회전 적용