我正在用VR手的位置旋转一个对象。问题是,相对于手的运动,物体旋转得很慢。是否有可能增加四元数的速度,使它旋转得更快,我可以控制速度?
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;
}
}
}
如何使用Quaternion.SlerpUnclamped
。我不太清楚你的代码。但是你可以这样使用它:
...
var appliedRotation = ...
var scaledAppliedRotation = Quaternion.SlerpUnclamped(Quaternion.identity, appliedRotation, rotateSpeed);
...
arotateSpeed
(0
)意味着我们不应用任何旋转(因为它将是单位四元数)。1
表示按1:1的比例应用appliedRotation
。