Hello Guest

Author Topic: Acceleration x axis not working  (Read 4408 times)

tunahantolga

  • Newbie
  • *
  • Posts: 12
    • View Profile
Acceleration x axis not working
« on: July 25, 2013, 01:41:21 pm »
Hello,

I bought a new Toolkit 2D so I don't know everything.

I am making jumping game and I have a problem.(I am using Unity 4 and 2D Toolkit.) I want to acceleration x axis on character.Normally function is running  in Unity but if I use  2D Toolkit is not running.Character is a sprite.Acceleration code is attached in character.

Here is the code:

    public float speed = -10.0F;
    private Vector3 dir;

       void Update () {

        Vector3 dir = Vector3.zero;
        dir.x = -Input.acceleration.x;
        dir.z = 0;

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

        dir *= Time.deltaTime;

        transform.Translate(dir * speed);

        Debug.Log(dir.x);
}


unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Acceleration x axis not working
« Reply #1 on: July 25, 2013, 01:53:55 pm »
Are you using the tk2dCamera? How much do you have to move your sprite for the change to be visible? Make sure dir is in the similar order of magnitude. If you need to move by 1 world unit for a noticable movement on the sprite, make sure dir isn't adding 0.01 instead.

tunahantolga

  • Newbie
  • *
  • Posts: 12
    • View Profile
Re: Acceleration x axis not working
« Reply #2 on: July 25, 2013, 03:50:11 pm »
Thank you! but I have a problem, this is a last question. I want to make a debug on android tablet.Normally is debugging in tablet after I use to 2D Toolkit was not running.

I am using tk2dCamera but scene has got a camera preview and tk2dCamera preview.

unikronsoftware

  • Administrator
  • Hero Member
  • *****
  • Posts: 9709
    • View Profile
Re: Acceleration x axis not working
« Reply #3 on: July 25, 2013, 05:50:02 pm »
That is because of a long standing bug in Unity, that has been fixed in Unity 4.2.
If you get 2D Toolkit 2.1 as well, that fixes the issue for older versions of Unity.