x


Input.acceleration on sphere with rigidbody(gravity)

I am making a school project, where I controll an sphere with devices accelerometer. Now everithing goes well, till I add rigidbody to the sphere. Sphere dose move according to the information from accelerometer for few moments, but then it starts to get stuck. Like it would get stuck in the ground(cube in my case).

I am using this code for accelerometer:

 //move object using accelerometer

var speed = 10.0;


function Update () {

    var dir : Vector3 = Vector3.zero;

    dir.x = -Input.acceleration.y;
    dir.z = Input.acceleration.x;

    if(dir.sqrMagnitude > 1)
       dir.Normalize();


    dir *= Time.deltaTime;

    transform.Translate(dir * speed);

}

How can I get this to work. Or is there a different way to apply movement to the object with information from accelerometer and have gravity.

I am developing with JavaScript for Android 2.2

more ▼

asked Apr 11 '12 at 06:29 PM

kkrulec gravatar image

kkrulec
0 1 1 1

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3460
x1790
x461
x139
x108

asked: Apr 11 '12 at 06:29 PM

Seen: 741 times

Last Updated: Apr 11 '12 at 06:29 PM