如何使用 LookRotation 根据手部位置旋转对象?
我正在为VR游戏创建一个交互系统,并且正在努力进行两种手相互作用。我正在使用 quaternion.quaternion.lookrotation.lookrotation.lookrotation()
方法是根据手的位置和旋转生成抓取对象的旋转的方法。前部很简单:
Vector3 fwd = (primaryHand.position - secondaryHand.position).normalized;
“向上”部分是我遇到的困难。最初,我尝试使用双手的平均向上方向:
Vector3 avgUp = Quaternion.Slerp(primaryHand.rotation, secondaryHand.rotation, 0.5f) * Vector3.up;
这种方法存在问题:手的向量向量可能与fwd
向量对齐,这会导致对象在过去时翻转它。这是问题的简单说明: 浅绿色箭头表示手的向上方向,而深绿色是用作
lookrotation()
方法的参数的计算方向。
显而易见的解决方案似乎是选择另一个固定向量而不是“向上”,该向量与fwd
向量不容易对齐。在示例中,它可能是与手指对齐的矢量。但是请记住,初始旋转没有限制,因此无论您选择哪种矢量,始终都会旋转旋转,以使矢量对齐。即使您动态选择最佳矢量(垂直于fwd
>),与fwd
对齐相比,它仍然充其量仍然是90度。
为了解决这个问题,我尝试将方向限制为不会引起问题的值,但这引起了另一个问题(我很难确定哪些值可以,哪些值应丢弃)。我觉得我在这里做错了什么,对这个问题有更好的解决方案吗?
I'm creating an interaction system for a VR game and I'm struggling with two hand interactions. I'm using the Quaternion.LookRotation()
method to generate the rotation of the grabbed object based on the positions and rotations of the hands. The forward part is pretty simple:
Vector3 fwd = (primaryHand.position - secondaryHand.position).normalized;
The "up" part is what I have difficulty with. Initially I tried using the average up direction of both hands:
Vector3 avgUp = Quaternion.Slerp(primaryHand.rotation, secondaryHand.rotation, 0.5f) * Vector3.up;
There is an issue with this approach: the hand's up vector might get aligned with the fwd
vector, which causes the object to flip over when it goes over it. Here is a simple illustration of the problem:
The light green arrows represent the up direction of the hands, while the dark green is the calculated direction used as an argument for the LookRotation()
method.
The obvious solution seems to be to pick a different fixed vector instead of "up", one which won't be so easily aligned with the fwd
vector. In the example it could be a vector aligned with the fingers. But keep in mind that there are no restrictions on initial hand rotation so no matter which vector you choose the hands can always happen to be rotated so that the vectors align. And even if you pick the an optimal vector dynamically (one that is perpendicular to fwd
), it's still at best 90 degrees from aligning with fwd
.
To solve this I tried restricting the direction to the values which don't cause problems but this caused another issues (I had difficulties with determining which values are ok and which should be discarded). I feel like I'm doing something wrong here, is there any better solution to this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以计算手的三角洲旋转并将其应用于对象的“基础”(如果我们只考虑到手的位置的变化,则新的是……当然,这与轴是正交的对象)。然后确定角度变化,从而导致每只手旋转的角度。平均这些角度,然后使用QUATERNION.ANGLEAXIS将这些角度施加到较早的“基础”上。然后,您可以向前及以进行quaternion.lookrotation)。
以下是如何使用此功能的示例,包括VR手噪声模拟。要查看测试,请在Unity中创建一个新场景,然后将其附加到相机上,它将在游戏开始时构建场景。有一个抓地力/发行GUI将出现在Play View中。您可以调整场景中的手旋转
You can calculate the delta rotations of the hands and apply it to the "base up" of the object (the new up if we only take into account the change in position of hands...which will of course be orthogonal to the axis of the object). Then determine the change in angle that results in that up being rotated with each hand. Average those angles out, then apply those angles with the hand-hand axis using Quaternion.AngleAxis to the "base up" from earlier. Then you have your forward and up for Quaternion.LookRotation).
Below is an example of how you can use this, including VR hand noise simulation. To see the test, create a new scene in unity and attach this to the camera and it will build the scene on play start. There is a grip/release gui that will appear in Play view. You can adjust the hand rotation in Scene view