Hi everybody,
I scripted a slider to transform the x axis rotation of a DirectLight from 0º to 180º. It works fine until the handle of the slider passes the value of 1.2 approximately (max value is set to 1.8). Then if I move it backwards the rotation doesn’t update until it reaches the beginning, then the value suddenly turns to 0. Also, it reaches the 180º limit at that same 1.2 value, not at 1.8 as one would expect. I’m quite new to programming so the answer might be quite obvious…

This is my script:

using UnityEngine;
using System.Collections;
using UnityEngine.UI;

Since you are doing decimal places and setting the x value, you’ll need to multiply your value to get the angle. Or, just set your slider to go from 0-180.

I tried using that technique before to no success: Set the slider range to 0-180 and modified the script to use Euler (I think). Now the problem i get is that past 90º the rotation becomes quite weird. I read it is due to the gimbal effect. This is the script now:

Don’t mean to step on any toes, but I think that may be working with a little luck
I would think you want the ‘y’ and ‘z’ values in the Euler to be eulerAngles

Certainly not stepping on toes. I did a quick test on x only.

If I do a test in update where I have three public floats in the inspector and an Update method that sets the x, y, z rotation of the Quaternion.Euler, I’m getting the behavior I would expect.

public float xpos;
public float ypos;
public float zpos;
private void Update()
{
transform.localRotation = Quaternion.Euler(xpos, ypos, zpos);
}

So if I increase the values positive it spins one way, if I go negative, it spins the other way. It appears to work on all three values. But, that doesn’t mean there aren’t issues with this.

Totally… and for 3 values , as well I would expect that to work

I think , in your previous example , though, you were passing Quaternion ‘y’ and ‘z’ to the Euler method, which is why I said I think it’s working with luck …

hmm…I think I understand, but in this case it might not matter. Euler just takes 3 floats or a vector3. The first line may not matter and it may just be simply getting the values of y and z and passing them to Euler is enough.

But I think I understand, if the localRotation doesn’t return numbers you’d expect, you might get odd results.

Right… I know almost nothing about Quaternions, but I’m fairly sure if y and z were ‘0’ it would work perfectly.
I am also fairly sure that the range of float values for y/z of a Quat is not the same as the values you could put into Euler. That’s all I meant

I’d have to test the to see, but since Quaternion is what localRotation returns. It might be fine. But I haven’t messed with them much myself. I’ll have to play with it sometime.

I didn’t see crazy flicker, but when trying eulerAngles on my own I am encountering some weird behaviour lol

So, while I can say the quaternion.y, and.z values aren’t good for Euler , I am totally lost about the rest.
That’s something I’d like to figure out the answer to, because I always suggest that to people (and myself) lol

I tried a bit longer; on the ‘y’ axis things seemed more stable (maybe a coincidence).

However, since the OP said it’s working, I’m going to let it go! lol
I would love to figure this out a bit better, but never meant to hijack the thread

For completeness:
Do not retrieve and re-use eulerangles in calculations for quaternions! lol

multiply the quaternion by the changed value (of the axis) (I am pretty sure this is correct)
or store each value (of euler angles), and adjust those as needed and re-apply to Quaternion.Euler to create the rotation. ( I am positive this works correctly)