【发布时间】:2018-06-26 12:21:23
【问题描述】:
嗨,我正在尝试一个始终在北方向的模型。如何在现实世界中获得北极方向。
public class PointNoeth : MonoBehaviour {
// Use this for initialization
//void Start ()
IEnumerator Start()
{
// First, check if user has location service enabled
if (!Input.location.isEnabledByUser)
yield break;
// Start service before querying location
Input.location.Start();
// Wait until service initializes
int maxWait = 20;
while (Input.location.status == LocationServiceStatus.Initializing && maxWait > 0)
{
yield return new WaitForSeconds(1);
maxWait--;
}
// Service didn't initialize in 20 seconds
if (maxWait < 1)
{
print("Timed out");
yield break;
}
// Connection has failed
if (Input.location.status == LocationServiceStatus.Failed)
{
print("Unable to determine device location");
yield break;
}
else
{
// Access granted and location value could be retrieved
print("Location: " + Input.location.lastData.latitude + " " + Input.location.lastData.longitude + " " + Input.location.lastData.altitude + " " + Input.location.lastData.horizontalAccuracy + " " + Input.location.lastData.timestamp);
}
// Stop service if there is no need to query location updates continuously
Input.location.Stop();
Input.compass.enabled = true;
}
// Update is called once per frame
void Update ()
{
transform.rotation = Quaternion.Euler(0, -Input.compass.trueHeading, 0);
/
}
}
在更新功能中,我设置了旋转。我将箭头标记作为我的模型。最初我让它指向 z 方向,但是当我点击播放时,它变为 -x 轴。当我签入我的时也会发生同样的情况设备。当我使用手机中的工具检查现实世界的北极时,它的方向是相反的。那么如何将我的模型指向北极。
【问题讨论】:
-
好吧,在编辑器中,你的对象被旋转到
(90, 0, -90),你的代码告诉它旋转到(0, $heading, 0)...
标签: c# unity3d orientation