void Update () {
    transform.position += transform.forward * 0.1f;
    float temp = Input.acceleration.x;
    float z = Input.acceleration.z;
    float x = Input.acceleration.x;
    float y = Input.acceleration.y;
    //Debug.Log (temp);
    transform.Translate (0,-y * speed * Time.deltaTime, 0);
    transform.Translate (-x * speed * Time.deltaTime,0, 0);
    transform.Rotate (0,0,-temp * speed);

The rotation seems to work fine, but when I tilt the phone, nothing happens to the plane's position in space. What's wrong?

EDIT: I know there are some silly aspects to the code, just bear with me while I debug it.

I also think it has something to do with the plane's constant velocity in the top of the code, but I don't know how to make it move with a constant speed forward but still let the user change the Z-Y coordinates via tilting.

  • \$\begingroup\$ I have verified that your code works, but based off your other questions, I am still sure you have a problem. Unfortunately, its not here. Adding that code to a cube in an empty project, the cube moves, although sporadically. Perhaps your speed value is so low that movement is simply unnoticeable? I might suggest also adding a Debug.Log(Input.acceleration.x to your update, just to confirm your phones accelerometer is not in fact faulty (always good to cross off the low-chance-but-possible stuff, as eventually it will bite you) \$\endgroup\$
    – Gnemlock
    Aug 18, 2016 at 15:30
  • \$\begingroup\$ As for your translate code, you can make it easier to read (for you and others) by working out the last translation vector, and applying it in one go. Something like float x = yInput * speed * deltaTime; floaty = xInput * speed * deltaTime; transform.Translate(x, y, z). \$\endgroup\$
    – Gnemlock
    Aug 18, 2016 at 15:32
  • \$\begingroup\$ Try and comment out as much code as you can, in your entire class, while still applying input. If you work out the problem, great. Post what lines you commented out to stop the problem. If not, post the entire class. Im not sure how others feel about "code dumps", but Im happy to look through it sometime tomorrow(today) and clean it up/work it out for you \$\endgroup\$
    – Gnemlock
    Aug 18, 2016 at 15:34

1 Answer 1


Instead of trying to have some crazy math to move the plane, try it first with a set speed whenever you tilt the phone. Then, try adding a if and else if that changes the speed depending on the angle of tilt. I've always seen that it's easier to build on to a script than to do it as complex as possible first.

  • \$\begingroup\$ Its inefficient.. but its pretty basic math for moving the plane. Especially considering the asker appears to be studying a mathematics degree (not to imply you should know that, but it is a factor brought up in another of their questions) \$\endgroup\$
    – Gnemlock
    Aug 18, 2016 at 15:26

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .