- Home /
Question by
jack_sparrow · Mar 22, 2012 at 07:06 AM ·
androidaccelerometertilt
roll ball in two axis using devices accelerometer.
Hi, every one
I want to make simple roll ball game in android.
I have a script but it can only use x axis to roll ball using accelerometer. can you help me too roll ball in two axis.
here's the code..
function Update () {
var dir : Vector3 = Vector3.zero;
dir.x = -Input.acceleration.y*.5;
transform.position.x += dir.x;
}
Thanx
Comment
Best Answer
Answer by DaveA · Mar 22, 2012 at 07:07 AM
Just guessing:
function Update () {
var dir : Vector3 = Vector3.zero;
dir.x = -Input.acceleration.y*.5;
transform.position.x += dir.x;
dir.y = -Input.acceleration.x*.5;
transform.position.y += dir.y;
}
Thanx for replay Dave A
Code is Working but y axis is giving opposite result.
Can you fix this ?
thanx again
Well try removing the negative sign before the Input.acceleration.x.... just suggesting..