- Home /
[Accelerometer] Problem with the Reference code Snippet
Hello Everybody, i'm using the Scripting reference code snippet for the Input.acceleration to move my player using a Nexus S accelerometer. http://docs.unity3d.com/Documentation/ScriptReference/Input-acceleration.html
but i'm stuck with 2 problems. the first one is that my object Doesn't move if i use the dir *= Time.deltaTime the second one, when i don't use the time.deltaTime. my object is moving but it's very unstable and doesn't stop shaking.
function Update () { /* // Moving the player with Cursor/Touch here: transform.position.x = Camera.main.ScreenToWorldPoint(Input.mousePosition).x; transform.position.y = Camera.main.ScreenToWorldPoint(Input.mousePosition).y; transform.position.x = Mathf.Clamp(transform.position.x, -3.5, 3.5); // limite les bordures de l'ecran transform.position.y = Mathf.Clamp(transform.position.y, -5.41, 5.4); */ //Moving the player with Accelerometer here: var dir : Vector3 = Vector3.zero; dir.x = Input.acceleration.y; dir.y = Input.acceleration.x;
if (dir.sqrMagnitude > 1){ dir.Normalize(); }
transform.Translate(dir * movSpeed); if (death == true){ // My Loose Condition check to restart the game RestartGame(); } }
Thanks in Advance !!!
Your answer
Follow this Question
Related Questions
Gyroscope.userAcceleration returning zero 0 Answers
How to get a force from acceleromoters instead of angle? 0 Answers
Unity3D cross-platform input wireless 1 Answer
why cant I get android accelerometer working in two planes? 3 Answers
Android tilt controls - taking player direction into consideration 2 Answers