我正在用我的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;
}
}
}
1条答案
按热度按时间v9tzhpje1#
使用
Quaternion.SlerpUnclamped
怎么样?我不太确定你的代码。但你可以这样使用它:0
的rotateSpeed
意味着我们不应用任何旋转(因为它将是恒等四元数)。1
意味着appliedRotation
以1:1的比例应用。任何更大或更小的值都会相应地改变旋转量。