【发布时间】:2018-01-21 01:08:29
【问题描述】:
这是我到目前为止编写的代码,它用于围绕空间中的一个点运行的相机。
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Lean.Touch;
public class CameraOrbit : TopClass
{
[Tooltip("Ignore fingers with StartedOverGui?")]
public bool ignoreGuiFingers = true;
[Tooltip("Ignore fingers if the finger count doesn't match? (0 = any)")]
public int requiredFingerCount = 1;
[Tooltip("The sensitivity of the movement, use -1 to invert")]
public float sensitivity = 0.25f;
public Vector3 target = Vector3.zero;
protected void LateUpdate()
{
// Get the fingers we want to use
List<LeanFinger> fingers = LeanTouch.GetFingers(ignoreGuiFingers, requiredFingerCount);
// Get the scaled delta of all the fingers
Vector2 delta = LeanGesture.GetScaledDelta(fingers);
transform.RotateAround(target, Vector3.up, delta.x * sensitivity);
transform.RotateAround(target, Vector3.right, delta.y * sensitivity);
transform.LookAt(target);
}
}
到目前为止效果很好,但是有两件事很烦人,我不知道如何解决
- 最大的问题是当相机到达顶部时,如果用户不断向上移动,事情会变得很奇怪。相机开始旋转,世界旋转等等...我希望相机在接近顶部或底部时停止。
- 相机的旋转可能会变得很奇怪,我希望它始终指向上方,并且永远不会稍微或完全向右或向左旋转,尤其是倒置。总是向上。
经过大量 Google 搜索后,我尝试了这些链接
- http://wiki.unity3d.com/index.php?title=MouseOrbitImproved
- https://answers.unity.com/questions/363353/how-to-limit-a-transform-movement-in-x-axis.html
- https://answers.unity.com/questions/438836/limit-camera-rotation-with-rotatearound.html
- https://answers.unity.com/questions/1087351/limit-vertical-rotation-of-camera.html
- https://answers.unity.com/questions/1370422/limit-y-axis-transformrotatearound.html
但它们都不能正常工作,或者我无法让它们适应我的需要
任何帮助都会很棒,在此先感谢
【问题讨论】:
-
好吧,在你旋转之前,检查你已经处于什么角度,然后相应地旋转(全帧旋转,只有剩余的角度,甚至根本没有)你遇到的怪异可能是云台锁定。 de.wikipedia.org/wiki/Gimbal_Lock
-
@yes 如何检查我的角度以及全帧旋转以及您所说的其他内容?
-
全帧旋转是指帧中可能发生的最大旋转。
标签: c# unity3d rotation unity5 quaternions