unity3d - Accelerometer sensitivity

sooon

I am testing the accelerometer code in Unity3D 4.3. What I want to do is simple change the object angle while tilting the ipad, to fake view angle like real live. Everything works fine except for the fact that the accelerometer is a bit too sensitive and I can see the GameObject is like of flickering even I put it on table. How can I make it less sensitive so that even when you hold with your hand the angle will change according to the tilt and the object remain steady?

Here are my code:

void Update () {
        Vector3 dir = Vector3.zero;

        dir.x = Mathf.Round(Input.acceleration.x * 1000.0f) / 1000.0f;
        dir.y = Mathf.Round(Input.acceleration.y * 1000.0f) / 1000.0f;
        dir.z = Mathf.Round(Input.acceleration.z * 1000.0f) / 1000.0f;

        // clamp acceleration vector to the unit sphere
        if (dir.sqrMagnitude > 1)
            dir.Normalize();

        // Make it move 10 meters per second instead of 10 meters per frame...
        dir *= Time.deltaTime;
        dir *= speed;

        acx = dir.x;
        acy = dir.y;
        acz = dir.z;
        transform.rotation = Quaternion.Euler(dir.y-20, -dir.x, 0);
    }
Kay

You may need to use a low pass filter (s. Exponential Moving Average for a better description regarding software) before using the signal output. I always use native code to get accelerometer and gyroscope values on iPhone so I am not 100% sure how Unity handles this. But from what you are describing the values appear unfiltered.

A low pass filter calculate a weighted average from all your previous values. Having for example a filter factor on 0.1 your weighted average is:

Vector3 aNew = Input.acceleration;
a = 0.1 * aNew + 0.9 + a;

This way your values are smoothed at the expense of a small delay. Running the accelerometer with 50 Hz you won't notice it.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to increase the sensitivity of a 2D histogram in matplotlib?

From Dev

How to use accelerometer in cocos2d 3.0?

From Dev

Unity3d and Threading

From Dev

Meteor and Unity3D

From Dev

Using Android accelerometer y axis falls through terrain - Unity3D

From Dev

unity 3d rotate the gameobject according to accelerometer

From Dev

Android : Rotating a 3D object based on sensors : TYPE_ROTATION_VECTOR vs TYPE_ACCELEROMETER

From Dev

Is it possible to use the accelerometer of Surface Pro 3 via Qt?

From Dev

Unity 3D realistic accelerometer control

From Dev

SensorManager type Accelerometer not working on Galaxy Tab 3 Lit 7.0"

From Dev

Accelerometer QML

From Dev

nullreferenceexception : unity3d

From Dev

Unity3D: HighScore

From Dev

Three.JS: Move 3D cube with accelerometer data over x an y-axis

From Dev

Does the zero-value or sensitivity of an accelerometer changes over time?

From Dev

How to getting movement size from 3 axis accelerometer data

From Dev

unity3d - Accelerometer sensitivity

From Dev

unity 3d rotate the gameobject according to accelerometer

From Dev

Android : Rotating a 3D object based on sensors : TYPE_ROTATION_VECTOR vs TYPE_ACCELEROMETER

From Dev

Is it possible to use the accelerometer of Surface Pro 3 via Qt?

From Dev

Mouse sensitivity

From Dev

SensorManager type Accelerometer not working on Galaxy Tab 3 Lit 7.0"

From Dev

Accelerometer QML

From Dev

change openlayers3 zoom sensitivity

From Dev

ionic3 slides swipe sensitivity

From Dev

C# Unity3D Scale using Accelerometer with Clamp

From Dev

Unity - How To Disable Accelerometer?

From Dev

BLE Accelerometer

From Dev

Gear S3 accelerometer very slow

Related Related

HotTag

Archive