- Home /
moving an object with accelerometer using unity iphone.
Hello guys, I am pretty new with unity iPhone and i have to move an object with accelerometer. i have been goggling around for some tutorial but i have not got any. used the script of roll-a-ball example but that is not working as well.
if anyone can share a tutorial or some example of moving an object using accelerometer then i would be a great help.
thanks in advance.
What don't you understand about the tutorials? StarTrooper also utilizes the accelerometer.
Answer by KrisCadle · Jun 01, 2011 at 04:16 AM
from the script reference::
// Move object using accelerometer
var speed = 10.0;
function Update () {
var dir : Vector3 = Vector3.zero;
// we assume that device is held parallel to the ground
// and Home button is in the right hand
// remap device acceleration axis to game coordinates:
// 1) XY plane of the device is mapped onto XZ plane
// 2) rotated 90 degrees around Y axis
dir.x = -Input.acceleration.y;
dir.z = Input.acceleration.x;
// clamp acceleration vector to unit sphere
if (dir.sqrMagnitude > 1)
dir.Normalize();
// Make it move 10 meters per second instead of 10 meters per frame...
dir *= Time.deltaTime;
// Move object
transform.Translate (dir * speed);
}
Answer by eciosf · Aug 08, 2013 at 07:32 PM
In Unity 4.1 is not working. Any solution? When I compile in 3.5 has no problems, but I made a stupid opening my project in Unity 4.1 and I have to finish the game on it. Someone has the same difficulty?
Your answer
Follow this Question
Related Questions
External IMU data to control iOS game via BLE 0 Answers
accelerometer script but used while device in landscape mode? 1 Answer
Accelerometer question 1 Answer
Calabrate Accelerometer 1 Answer
Device Orientation Issue 1 Answer