[SOLVED] Gamepad axis input. How to make object's tilt be equal to tilt of thumstick ?

Using this code I was able to tilt it to the left - always to the left, even if I tilt thumb-stick moving to the right. And it’s not returns to initial position - it gets stuck at several degrees to the left.

float translation;

    public GameObject leftThumbstick;

    // Use this for initialization
    void Start () {
 
    }
 
    void Update () {
     translation= Input.GetAxis ("XAxis");
     leftThumbstick.transform.eulerAngles = new Vector3 (0, 0, translation * 10);
    }

The pots for analogue sticks in a controller rarely return to 0. This is why consoles apply a 20% deadzone to them by default.

I would do this with your if statement;

        translation = Input.GetAxis("XAxis");
        if (Mathf.Abs(translation) >= 0.2f)
        {
            leftThumbstick.transform.eulerAngles = new Vector3(0, 0, -translation * 10);
        }
        else
        {
            print(Input.GetAxis("XAxis"));
            leftThumbstick.transform.eulerAngles = Vector3.zero;
        }

Changes nothing. Tried different deadzone values.

Strange, that code works fine for me. add Debug.Log(translation) before the if statement and see what it is doing.

I was mistaken about axis name (I used another in Input Manager).
But anyway still not working.
When I push thumbstick to the left it says:
-0.9961242
And it doesn’t give new values after another pushes.
Also it gives this value and object tilts object to the left even if I push buttons on gamepad.

3063763--230277--Axis.png

What controller are you using? Maybe Unity is having an issue with it. I tried with an xbox controller and it worked as expected.

Mad Catz CTRL R

Here is the whole project:
https://drive.google.com/open?id=0B23z1X8aoz54WElNY2JlOEdyRGc
Here is complete code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class GamePadRenderer : MonoBehaviour {

    float speed = 0.01f;
    float translation;
    public GameObject aButton;
    public GameObject bButton;
    public GameObject xButton;
    public GameObject yButton;
    public GameObject leftThumbstick;

    // Use this for initialization
    void Start () {

    }

    // Update is called once per frame
    void Update () {

        if(Input.GetButton ("AButton")) {
            aButton.active = false;
        } else {
            aButton.active = true;
        }
        if(Input.GetButton ("BButton")) {
            bButton.active = false;
        } else {
            bButton.active = true;
        }
        if(Input.GetButton ("XButton")) {
            xButton.active = false;
        } else {
            xButton.active = true;
        }
        if(Input.GetButton ("YButton")) {
            yButton.active = false;
        } else {
            yButton.active = true;
        }

        translation = Input.GetAxis ("XAxis");
        Debug.Log (translation);

        if (Mathf.Abs(translation) >= 0.2f) {
            leftThumbstick.transform.eulerAngles = new Vector3 (0, 0, -translation * 10);
        } else {
            print (Input.GetAxis ("XAxis"));
            leftThumbstick.transform.eulerAngles = Vector3.zero;
        }

    }
}

I added Debug.Log(leftThumbstick.transform.eulerAngles) in the ‘if() {}’ - see values on screenshot (I turn joypad to the left and then to the right). Also I noticed ‘Bake paused in play mode’ message at right bottom corner.

XBox One controller works in Editor. MAD CATZ works with project on Android.