unity3d 向四元数添加速度

vbkedwbf  于 2023-04-21  发布在  其他
关注(0)|答案(1)|浏览(91)

我正在用我的VR Hand的位置旋转一个对象。问题是对象相对于手的移动旋转得很慢。是否可以为四元数添加速度,以便它旋转得更快,并且我可以控制速度?

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class RotateModel : MonoBehaviour {
    public bool triggerClicked = false;
    public Transform rightHand;
    private Quaternion initialObjectRotation;
    private Quaternion initialControllerRotation;
    private bool set = false;

    void Update () {
        if (triggerClicked) {
            if (set == false) {
                initialObjectRotation = transform.rotation;
                initialControllerRotation = rightHand.rotation;
                set = true;
            }
            Quaternion relativeRotation = Quaternion.Inverse(rightHand.rotation) * initialControllerRotation;
            transform.rotation = rightHand.rotation * relativeRotation;
        } else {
            set = false;
        }
    }
}
v9tzhpje

v9tzhpje1#

使用Quaternion.SlerpUnclamped怎么样?我不太确定你的代码。但你可以这样使用它:

...
var appliedRotation = ...
var scaledAppliedRotation = Quaternion.SlerpUnclamped(Quaternion.identity, appliedRotation, rotateSpeed);
...

0rotateSpeed意味着我们不应用任何旋转(因为它将是恒等四元数)。1意味着appliedRotation以1:1的比例应用。任何更大或更小的值都会相应地改变旋转量。

相关问题