简体   繁体   中英

Unity 3D game using accelorometer sensors

I need parallel movement with sensor position. How can I do that with 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. 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.

Here's a good starting point from Unity Documentation Gyroscope

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM