[1.0] LookAtTarget does not work correctly if a character isn't facing +Z at scene start (+ fix?)
Environments (please complete the following information):
- UniVRM version:
0.124.1 - Unity version:
Unity-2022.3.6f1 - OS:
Windows 10
Describe the bug
- video
https://github.com/vrm-c/UniVRM/assets/8168124/931ea800-e669-4f07-b31c-9eb0470f5132
-
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
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
#2427