统一 - 旋转的物体在使用四合一时以一种奇怪的方式翻转

发布于 2025-02-10 08:45:02 字数 439 浏览 1 评论 0原文

我正在尝试在VR中创建一个系统,其中对象旋转跟随玩家手的旋转。不幸的是,当手以高角度旋转时,旋转的物体以一种奇怪的方式翻转,好像旋转从360度变为0。不允许我根据以下方面更改“灵敏度”:

  • 1-目标是旋转1:1的比率
  • 2-目标的旋转是手的两倍等

// In FixedUpdate
Quaternion deltaRotation = Quaternion.Inverse(target.rotation) * hand.rotation;
deltaRotation.ToAngleAxis(out float angle, out Vector3 axis);
target.rotation *= Quaternion.AngleAxis(angle * sensitivity, axis);

任何帮助都将不胜感激!

I'm trying to create a system in VR in which an object rotation follows the rotation of the player's hand. Unfortunately, when the hand rotates at a high angle, the rotated object flips in a strange way as if it had a problem with the rotation change from 360 degrees to 0. I tried many ways to solve this problem, but each one that worked did not allow me to change "sensitivity" on the basis of:

  • 1 - target is rotating 1: 1 ratio with hand
  • 2 - target is rotating twice as much as hand

etc.

// In FixedUpdate
Quaternion deltaRotation = Quaternion.Inverse(target.rotation) * hand.rotation;
deltaRotation.ToAngleAxis(out float angle, out Vector3 axis);
target.rotation *= Quaternion.AngleAxis(angle * sensitivity, axis);

Any help would be appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

﹏半生如梦愿梦如真 2025-02-17 08:45:02

因此,问题在于,

Quaternion deltaRotation = Quaternion.Inverse(target.rotation) * hand.rotation;

如果灵敏度为!= 1这些对象旋转变得不同步,因此三角骨无法为您带来期望的价值。您可能想检查自上次帧以来的手旋转多少,这样:

Quaternion _lastFrameRotation;

void Awake()
{
    _lastFrameRotation = transform.rotation;
}

private void FixedUpdate()
{
    Quaternion deltaRotation = Quaternion.Inverse(_lastFrameRotation) * transform.rotation;
    deltaRotation.ToAngleAxis( out float angle, out Vector3 axis );
    target.rotation *= Quaternion.AngleAxis( angle * sensitivity, axis );

    _lastFrameRotation = transform.rotation;
}

So the problem is in

Quaternion deltaRotation = Quaternion.Inverse(target.rotation) * hand.rotation;

if the sensitivity is != 1 these objects rotations get desynchronized so the deltaRotation will not give you the value you expect. You probably wanted to check how much hand rotated since last frame, like that:

Quaternion _lastFrameRotation;

void Awake()
{
    _lastFrameRotation = transform.rotation;
}

private void FixedUpdate()
{
    Quaternion deltaRotation = Quaternion.Inverse(_lastFrameRotation) * transform.rotation;
    deltaRotation.ToAngleAxis( out float angle, out Vector3 axis );
    target.rotation *= Quaternion.AngleAxis( angle * sensitivity, axis );

    _lastFrameRotation = transform.rotation;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文