统一在最小和最大距离之间旋转
我试图让对象拖动成为可能。 这个对象只能旋转那么多。 (Similair到门口)。
这是编辑的代码,用于旋转有效的对象。 我有2个用于maxrotation和minrotation的载体。
只要用户拖动可交互对象,就会调用此代码。 (比如更新但仅在拖动时)
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语句会很棒。 我尝试了很多东西,但它仍然没有用。
如上所述,此处的代码粘贴有效。 对象应该是可拖动的,但只能达到某个点。
totransform是将被轮换的变换
任何想法都会很棒,也非常受欢迎。
亲切的问候。
我想你想看看eulerAngles 。 检查您获得的值,然后在执行旋转之前设置if语句。 这是一个示例代码,供您查找所需的值:
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)); } }
所以这是适合我的解决方案。 首先,我声明了运动变量(下面没有看到,在这种情况下是2)。 然后我跟踪覆盖的距离并对其进行限制。
当然这个代码有一些改进,比如使用移动代替2.但是由于时间限制,我没有做到。
if (GestureManager.Instance.IsNavigating && HandsManager.Instance.FocusedGameObject == gameObject) { //here we get the movement direction and set it in movement. if (GestureManager.Instance.NavigationPosition.y > 0) { movement = 2; } else if (GestureManager.Instance.NavigationPosition.y < 0) { movement = -2; } //the first part is false if we reach higher then maxdistance and the movement is going up //the second part is false if we reach the lower distance and the movement is going down. if ((!(distance > maxdistance.x) || movement < 0) && ((!(distance < mindistance.x) || movement > 0))) { //here we add the movement to the distance so we know if it gets closer or further distance += movement; //here we rotate totransform.Rotate(new Vector3(movement, 0, 0)); } }