Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Half of Input.acceleration in working

Discussion in 'Scripting' started by victorkhugo, Jun 28, 2014.

  1. victorkhugo

    victorkhugo

    Joined:
    Dec 4, 2013
    Posts:
    32
    I'm making a game for both iPhone and web player, and I've got the side to side movement working in landscape mode on the phone, but tilting the phone up and down does nothing. Everything works as expected in Web Player.

    Here is my JS code :
    Code (JavaScript):
    1. function Update () {
    2.         if (Input.GetKey("right") || Input.GetKey("d") || Input.acceleration.x>0) {
    3.             rigidbody.AddForce(floatSpeed,0,0);
    4.         }else if (Input.GetKey("left") || Input.GetKey("a") || Input.acceleration.x<0) {
    5.             rigidbody.AddForce(-floatSpeed,0,0);
    6.         }else if (Input.GetKey("up") || Input.GetKey("w") || Input.acceleration.y>0) {
    7.             rigidbody.AddForce(0,floatSpeed,0);
    8.         }else if (Input.GetKey("down") || Input.GetKey("s") || Input.acceleration.y<0) {
    9.             rigidbody.AddForce(0,-floatSpeed,0);
    10.         }
    11. }
     
    Last edited: Jun 28, 2014
  2. victorkhugo

    victorkhugo

    Joined:
    Dec 4, 2013
    Posts:
    32
    Wow do I feel stupid. I changed all the else ifs to just ifs and it works perfectly.
     
  3. Troas

    Troas

    Joined:
    Jan 26, 2013
    Posts:
    157
    Yea I'm not sure you can do that with movement. I've seen an issue like this before with multiple else ifs and the thing just wouldn't take.

    Maybe switch case will work and be a bit more optimal?