[英]Unity 3D game using accelorometer sensors
I need parallel movement with sensor position.我需要与传感器 position 平行移动。 How can I do that with Unity?
我怎么能用 Unity 做到这一点?
void Update()
{
transform.position += new Vector3(
Input.acceleration.x,
Input.acceleration.y,
Input.acceleration.z
);
Debug.Log(transform.position);
}
Perhaps you're mistaking accelerometer and gyroscope.也许你误会了加速度计和陀螺仪。 An accelerometer is used to calculate the speed in which a device was rotated.
加速度计用于计算设备旋转的速度。 Once it stops rotating, the accelerometer's value will be equivalent to Vector3.zero.
一旦停止旋转,加速度计的值将等于 Vector3.zero。 However, gyroscope returns the actual rotation of a device depending on its initial origin.
但是,陀螺仪会根据设备的初始原点返回设备的实际旋转。
What you will need is to know how a gyroscope works in Unity, and normalize its value from 0 to 1 because I believe it outputs angles (0 to 360), and start your movement from there.您需要了解陀螺仪在 Unity 中的工作原理,并将其值从 0 标准化为 1,因为我相信它会输出角度(0 到 360),然后从那里开始您的运动。
Here's a good starting point from Unity Documentation Gyroscope这是Unity Documentation Gyroscope的一个很好的起点
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.