目前我正在尝试编写一个脚本,将一个手柄的移动效果复制到另一个手柄上,以便只有一只手臂能使用的用户也能进行双边运动。如何将一个手柄的位置镜像到另一个手柄上,使两个手臂能够协调运动?
镜像y轴和z轴很容易,因为它们同时移动并且旋转很容易镜像。但是,我无法镜像x轴运动。我希望当一个手掌向外移动时,另一个手掌也会做同样的动作,并且两个手臂一起向内移动。你有什么办法可以实现这一点吗? 我附上了我的当前脚本。我还使用OVRCemeraRig脚本中的简单布尔逻辑禁用了非镜像控制器的位置跟踪,以防止运动停滞。 需要使用OVRCemeraRig,因为使用final IK
我尝试过计算工作手臂的x位置与另一只手臂的x位置之间的差值,然后将该差值加到另一只手臂上,但没有成功。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class VRMirror : MonoBehaviour
{
public bool mirrorLeft;
public bool mirrorRight;
public GameObject leftHand; //left hand anchor in OVRCameraRig
public GameObject rightHand; //right hand anchor from OVRCameraRig
void Start()
{
}
void FixedUpdate()
{
Transform left = leftHand.GetComponent<Transform>();
Transform right = rightHand.GetComponent<Transform>();
if (mirrorLeft)
{
Vector3 leftPos = left.position;
Quaternion leftRot = left.rotation;
leftRot.y = -leftRot.y;
right.position = leftPos;
right.rotation = leftRot;
}
else if (mirrorRight)
{
Vector3 rightPos = right.position;
Quaternion rightRot = right.rotation;
rightRot.y = -rightRot.y;
left.position = rightPos;
left.rotation = rightRot;
}
}
}
SetLookRotation
修改的是旋转的副本。我会将代码改为destTransform.rotation = Quaternion.LookRotation(forwardVec,upVec);
,假设你的左手本地轴像这样,而你的右手只有中指向-x
。 - Ruzihm