Rotation snapping to 180 degrees with transform.rotation

I’m directly getting input from my Horizontal axis and assigning it to quaternion.x which is then set as the rotation to my object.
but even the slightest change in the quaternion (less than 0.00001) snaps the rotation to 180 degrees on any axis.
Here’s my code:

		steer = Input.GetAxis("Horizontal");
		localRotation.x = steer;
		transform.rotation = localRotation;

Im trying to get the axis to directly controll the degrees of rotation on x axis.

I have two solutions in mind. I will do the extra work for you, just let me know one thing: Do you want this to rotate for as long as you hold the button down, or do you want this to have a max angle of rotation?

With maximum angles. I tried that with Mathf.clamp, but it changed nothing. im trying to copy a mobile device tilt axis to the angle of the game object with limits. THe tilt axis stuff is all worked out, its just the rotation itself that doesnt behave as expected.

then please show us Renderer of m_world ... update the above picture

1 Answer

1

Alright I have two answers for you.

First, is the one you asked for, using a maximum angle for your object. The drawback with using this one, is that you will not have control over how quickly your Input.GetAxis accellerates to 1 or -1.

    float maxAngle = 120;
    float steer;

    void FixedUpdate ()
    {
        Quaternion steer;
        steer = Quaternion.Euler(Input.GetAxis("Horizontal") * maxAngle, 0,0);
        transform.localRotation = steer;
    }

This second method simply rotates in the direction you are holding down, based on a fixed speed. Now, you can obviously alter this to your liking with an if statement to measure against the current rotation, so it has the potential to be a better solution if you need that rotation speed.

    float rotationSpeed = 10;
    float steer;

    void FixedUpdate()
    {
        steer += Input.GetAxis("Horizontal") * rotationSpeed;
        transform.localRotation = Quaternion.Euler(steer, 0, 0);
    }

Let me know how that goes for you. Good luck!

The first one works but its a bit jerky, i think i'll use somekind of treshold or lerp it to position. Anyways, Thanks for the help!

brother s/he is having problem with applying the material itself and not with texture

I added another picture to clarify hopefully

then i think the problem is that you are having problem loading material from resources ... i would advice you to make a public variable for material and drag drop your material from inspector ... if you still want to use your original approach then please make sure that your material is in Resources folder (or Resource folder, just a bit confused ^^)