# Acelerometer TUTORIAL?

Hi is ther a basic acelerometer tutorial
with unity - iphone please ?

thanks a lot !
note: any comments are welcome !

check out the example projects on the resource section of the website.
They will teach you all relevant things together with the documentation.

General: Accelerometer is represented through a Vector3 object that tells you the gravitational acceleration into the 3 dimensions.

So the Vector3 tells you into which direction from the center of the iphone “down” is which allows you define into which direction the iphone is looking at that moment.

thaks for your VERY FAST answer, i will try that you said.
thanks again !

In C# I do this and then associate the script with your player GameObject

``````using UnityEngine;
using System.Collections;

public class PlayerInput : MonoBehaviour
{
private Vector3 accel = Vector3.zero;
private Vector3 previousAccel = Vector3.zero;
private readonly float lowFilter = 0.1f;
private readonly float highFilter = 0.9f;

void Awake()
{
Debug.Log("PlayerInput.Awake");
}

public void FixedUpdate()
{
// Filter using IIR - infinite impulse response, i.e. y[n] = a*y[n-1] + b*x
accel = (lowFilter * previousAccel) + (highFilter * iPhoneInput.acceleration);
previousAccel = accel;

// blah blah
``````

I once found this description somewhere. I don’t recall the original author but it’s a good description of what axis corresponds to the physical movement of the iPhone.

``````/*
The meaning of X, Y, Z
X = Roll X corresponds to roll, or rotation around the axis that runs from your home button to your earpiece.
Values vary from 1.0 (rolled all the way to the left) to -1.0 (rolled all the way to the right).

Y = Pitch. Place your iPhone on the table and mentally draw a horizontal line about half-way down the screen.
That's the axis around which the Y value rotates.
Values go from 1.0 (the headphone jack straight down) to -1.0 (the headphone jack straight up).

Z = Face up/face down. I expected the Z value to correspond to yaw. And it does not.
It refers to whether your iPhone is face up (-1.0) or face down (1.0).
When placed on it side, either the side with the volume controls and ringer switch, or the side directly opposite, the Z value equates to 0.0.
*/
``````

Can someone convert the above C# script to UnityScript (JS).

Thanks…