单位在最小和最大距离之间旋转 [英] unity Rotate between min and max distance
问题描述
我正在尝试拖动一个对象.该对象只能旋转这么多. (Similair到门).
I'm trying to make it possible to drag an object. This object can only rotate so much. (Similair to a door).
这是对位进行编辑的代码,该代码旋转有效的对象. 我有2个向量用于最大旋转和最小旋转.
Here is the code abit edited that rotates an object which works. I have 2 vectors for maxrotation and minrotation.
每当用户拖动可交互对象时,就会调用此代码. (例如更新,但仅在拖动时显示)
This code will be called whenever the user is dragging the interactible object. (like update but only when dragged)
if (GestureManager.Instance.IsNavigating &&
HandsManager.Instance.FocusedGameObject == gameObject)
{
//speed and navigiation of rotation
float rotationFactor;
rotationFactor = ManipulationManager.Instance.ManipulationPosition.y * RotationSensitivity;
totransform.Rotate(new Vector3(rotationFactor, 0, 0));
}
如果我可以在这里使用if语句,那将是很棒的.我尝试了很多事情,但仍然无法正常工作.
It would be great if I could use an if statement here. And I tried quite some things but it's still not working.
如前所述,此处的代码粘贴有效.该对象应该是可拖动的,但只能拖动到一定程度.
As stated the code paste here works. The object should be dragable but only up to a certain points.
totransform是要旋转的变换
totransform is the transform that will be rotated
任何想法都将是伟大的,并且将受到赞赏.
Any ideas would be great and most appreciated.
亲切的问候.
推荐答案
I think you want to look at eulerAngles. Check the values you're getting then set an if-statement before doing the rotation. This is a sample code for you to find the values you want:
if (GestureManager.Instance.IsNavigating &&
HandsManager.Instance.FocusedGameObject == gameObject)
{
//speed and navigiation of rotation
float rotationFactor = ManipulationManager.Instance.ManipulationPosition.y * RotationSensitivity;
Debug.Log(totransform.eulerAngles);
if (totransform.eulerAngles.x < 100) {
totransform.Rotate(new Vector3(rotationFactor, 0, 0));
}
}
这篇关于单位在最小和最大距离之间旋转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!