Modifying eulerAngles with slider issues (c#)
I'm using a slider to rotate an object on the z axis. The slider has a value of 1-360 (Whole Numbers); when the slider is moved, I use that value for the eulerAngles z axis value. (NOTE: The object is part of a child/parent 'string' of objects and it should only ever rotate on the local z axis). This method is working for some objects in the 'string', but not others. When it's not working, the object I'm trying to rotate spins wildly on the z axis because the objects z value is not a reflection of the slider value (I tested this in the inspector). I can't figure where these 'random' slider values are coming from.
Here is the rotation function I'm using for the sliders On Value Change event:
public void SliderRotate () {
Target.transform.eulerAngles = new Vector3(
Target.transform.eulerAngles.x,
Target.transform.eulerAngles.y,
mySlider.GetComponent<Slider> ().value);
}
BTW - If I change the x and y values to zero, the problem goes away. However, the objects then loose their correct orientation to their parent (I need the x and y to stay where they are).
Thanks in advance for any insight you can offer into this issue.
Windows - Unity 5.3.5f1
Here is an image that might help clarify the issue. Each pipe and fitting that is added to the chain, needs to rotate relative to the previous part; as if it were attached:
Answer by campbal · Aug 30, 2016 at 06:21 PM
After a lot of pain, the answer turned out to be simple: Instead of using "eulerAngles", I needed to use "localEulerAngles":
public void SliderRotate () {
Target.transform.localEulerAngles = new Vector3(
Target.transform.localEulerAngles.x,
Target.transform.localEulerAngles.y,
mySlider.GetComponent<Slider> ().value);
}
Answer by Rob2309 · Aug 26, 2016 at 03:57 PM
Maybe Target.transform.localRotation.eulerAngles will do the trick?
I appreciate the suggestion. Unfortunately, doesn't work.
Any other ideas? I'll try just about anything at this point.
Your answer
Follow this Question
Related Questions
I need help in rotating cube by 90 degree with swipe in all axis 0 Answers
transform.eulerAngles not working 2 Answers
Slider problem 1 Answer
[SOLVED!] PlayerPrefabs SetFloat and GetFloat is not working 0 Answers
Wrong .rotation.eulerAngles.x output 1 Answer