vrm-c / UniVRM

UniVRM is a gltf-based VRM format implementation for Unity. English is here https://vrm.dev/en/ . 日本語 はこちら https://vrm.dev/
https://vrm.dev/en
MIT License
2.61k stars 421 forks source link

[1.0] LookAtTarget does not work correctly if a character isn't facing +Z at scene start (+ fix?) #2345

Open exqt opened 3 months ago

exqt commented 3 months ago

Environments (please complete the following information):

Describe the bug

https://github.com/vrm-c/UniVRM/assets/8168124/931ea800-e669-4f07-b31c-9eb0470f5132

VRM10\Runtime\Components\Vrm10Runtime\Vrm10RuntimeLookAt.cs

        private static Transform InitializeLookAtOriginTransform(Transform rawHead, Transform actualHead, Vector3 eyeOffsetValue)
        {
            // NOTE: このメソッドを実行するとき、モデル全体は初期姿勢(T-Pose)でなければならない。
            var lookAtOrigin = new GameObject("_look_at_origin_").transform;
            lookAtOrigin.SetParent(actualHead);
            lookAtOrigin.position = rawHead.TransformPoint(eyeOffsetValue);
-           lookAtOrigin.rotation = Quaternion.identity;
+           lookAtOrigin.localRotation = Quaternion.identity;

            return lookAtOrigin;
        }

VRM10\Runtime\Components\LookAt\LookAtEyeDirectionApplicableToBone.cs

        public LookAtEyeDirectionApplicableToBone(Transform leftEye, Transform rightEye,
            CurveMapper horizontalOuter, CurveMapper horizontalInner, CurveMapper verticalDown, CurveMapper verticalUp)
        {
            _leftEye = leftEye;
-           var leftEyeRotation = _leftEye.rotation;
+           var leftEyeRotation = _leftEye.localRotation;
            _leftEyePreMultiplyRotation = _leftEye.localRotation * Quaternion.Inverse(leftEyeRotation);
            _leftEyePostMultiplyRotation = leftEyeRotation;

            // and same for rightEye
shingotabuchi commented 1 month ago

Thanks I am facing the same problem and this helped me.

UniVRM version: 0.125.0 Unity version: Unity-2022.3.40f1 OS: Windows 11

ousttrue commented 1 month ago

2427