【发布时间】:2014-09-06 10:30:25
【问题描述】:
n00b 问题,我什至还没有理解到能够很好地谷歌(或正确理解答案)。
我正在探索 Unity 3D 并使用陀螺仪输入问题是陀螺仪的每个轴都返回介于 -1 和 +1 之间的值,其中 0 是启用陀螺仪时的设备方向,其中 +1 和 -1 共享边框(如表盘上的 12)。但是,启用陀螺仪时,陀螺仪的 0,0,0 点不会被重置。统一论坛建议停用然后重新激活陀螺仪会有所帮助 - 它没有。
实际上,陀螺仪的 0 点在当前版本的 iOS 和 Unity 中是静态的,这意味着我需要“偏移”它以考虑手机的起始位置。
我的计划是:
var GyroOffset : Quaternion;
var CurrentGyroAttitude : Quaternion;
var DeadSpotXPos : float;
var DeadSpotXPos : float;
var ThresholdPos : float;
var ThresholdNeg : float;
function Start() {
Input.gyro.enabled = true;
Input.gyro.UpdateInterval = 0.001;
GyroOffset = Input.gryo.attitude;
}
function Update() {
CurrentGyroAttitude = input.gyro.attitude - GyroOffset;
if (CurrentGyroAttitude.x > ThresholdPos) DoSomething(1);
if (CurrentGyroAttitude.x < ThresholdNeg) DoSomething(-1);
if (CurrentGyroAttitude.x > DeadSpotXPos &&
CurrentGyroAttitude.X < ThresholdPos) DoSomethingElse(1);
if (CurrentGyroAttitude.x < DeadSpotXNeg &&
CurrentGyroAttitude.x < ThresholdNeg) DoSomethingElse(-1);
}
* DoSomething(arbitraryFloat) 和 DoSomethingElse(anotherArbitraryFloat) 做我想做的事情,而任意浮点数与陀螺仪输出无关。
由于 Gyro 输出介于 -1 和 +1 之间,我们可能会遇到 CurrentGyroAttitude.x 可以合法地为 -2 或 +2 的情况。这个计划的问题是我必须“偏移”到我的阈值和死点,这对于调整目的来说变得“不整洁”。我宁愿只操纵 CurrentGyroAttitude。
但是,我不知道如何在 UnityScript 中执行“钟面艺术”。我想我说的是模数数学,但我一直在遇到关于加密的复杂数学,这让我很头疼。:)
一旦“偏移”生效,谁能指导我“清理”陀螺仪姿态输出,使我的清理输出保持在 -1 和 +1 之间?
顺便说一句,如果有人能阐明 Unity 的 GyroUpdateInterval,那就太棒了,因为文档没有解释更新的衡量标准,或者操作的效果是什么。
【问题讨论】:
标签: android ios unity3d unityscript gyroscope