Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
exqt opened this issue Jul 4, 2024 · 2 comments
Labels
bug Something isn't working
Milestone

Comments

@exqt
Copy link

exqt commented Jul 4, 2024

Environments (please complete the following information):

  • UniVRM version: 0.124.1
  • Unity version: Unity-2022.3.6f1
  • OS: Windows 10

Describe the bug

  • video
output.mp4
  • A clear and concise description of what the bug is.
    In the video, the root object contains a VRM character, and LookAtTarget works well initially.
    However, after I rotated the root object and start the scene, LookAtTarget breaks.

  • Potential fix
    I believe this bug occurs because some lookAt related code uses world rotation instead of local rotation. Here is a fix I found:

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
@exqt exqt added the bug Something isn't working label Jul 4, 2024
@exqt exqt changed the title [1.0] LookAtTarget Does Not Work Correctly if VRM Model is Not Facing +Z at Scene Start Jul 5, 2024
@shingotabuchi
Copy link

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
Copy link
Contributor

ousttrue commented Sep 5, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
3 participants