Search Unity

Accelerometer Problem

Discussion in 'iOS and tvOS' started by aakaash, Jul 17, 2010.

  1. aakaash

    aakaash

    Joined:
    Jun 28, 2009
    Posts:
    38
    Hello,
    I have just finished making my first game in unity, which is based off a few tutorials. I am trying to convert this game into an iPhone game.

    The finger nicely replaces the mouse. However, the keyboard controls cannot be converted. The game is a top down strategy based game made using sprites (Sorry if i am not technically correct, after all i am a newbie :D ) Hence, i cannot use any of the control setups that come with unity iPhone. Could you please help me or point me to the direction where i can learn how to create a basic joystick/accelerometer control which overrides the W,A,S,D controls.

    The problem is that the script from the tutorial was made in c#. Hence, i need a script through which i can override the normal keyboard controls to either joystick/accelerometer. Thank you in advance for all your help. Any help in this context will be greatly appreciated.

    UPDATE: Have kind of got it working please see below for more details
     
  2. aakaash

    aakaash

    Joined:
    Jun 28, 2009
    Posts:
    38
    Wow ! nobody. Okay just an update tried all the scripts that come with the iPhone standard assets. After a lot of playing around got some of them working. But very very buggy. Then tried the accelerometer script in the manual. It worked flawlessly with Unity Remote but after building and running the app i realized that the users will have to keep their Phones/iPads(Worked Better) flat on a surface and then play. is there anyway i can just move up down right left more easily ?
     
  3. aakaash

    aakaash

    Joined:
    Jun 28, 2009
    Posts:
    38
    K so the accelerometer is finally moving after i used the following script.

    Code (csharp):
    1.  
    2. var speed = 10.0;
    3. function Update () {
    4. var dir : Vector3 = Vector3.zero;
    5. dir.x = -iPhoneInput.acceleration.y;
    6. dir.z = iPhoneInput.acceleration.x;
    7. if (dir.sqrMagnitude > 1)
    8. dir.Normalize();
    9. dir *= Time.deltaTime;
    10. transform.Translate (dir * speed, Space.World);
    11. }
    12.  
    Now the problem is as follows :-
    If i hold the device parallel to the ground with the home button on the right hand. The player moves as follows:-
    Right(Home Button) becomes up
    Left becomes down
    Up becomes left and
    Down becomes right.

    How can i fix this? Thanks in advance.
     
  4. Moonjump

    Moonjump

    Joined:
    Apr 15, 2010
    Posts:
    2,572
  5. aakaash

    aakaash

    Joined:
    Jun 28, 2009
    Posts:
    38
    Thanks a lot for all your help. FIxed the script by changing the z and x axis :D
     
  6. pavees

    pavees

    Joined:
    Jan 1, 2009
    Posts:
    116
    why didnt u try it by changing the Player Settings?? wer u can set it as Landscape mode of playing

    ie In Unity Menu:: Edit--> Project Setting--> Player--> Default Screen Orientation--> <<set it to wat ever u like>> u have 4 option on it.