- Home /
Set Rotation on Multiple Axis
I'm struggling to get my head around the rotation of my object.
I'm trying to make an Eye Ball system, that blinks, and has emotion that is done via a hemisphere (eye lid).
The blink (open/close of the hemisphere) is a rotation from 0 to -180 set on the X rotation axis. This works fine:
[Range(0f, 1f)]
public float _eyeClosed = 1f;
void UpdateEyeLids(){
float _blink = (180 * _eyeClosed);
_leftLid.eulerAngles = new Vector3(-_blink, 0, 0);
_rightLid.eulerAngles = new Vector3(-_blink, 0, 0);
}
So when my Range is set to 0, the eye is fully open, and when set to 1, the eye is fully closed. Like I said, this works perfectly.
However, the problem occurs when I want to add another rotation into the mix, locally, on the Y axis which is used for emotion (angry/sad). If I remove the blink system, and replace it with my emotion system, it works fine:
//-1 Sad | 0 Normal | 1 Angry
[Range(-1f, 1f)]
public float _eyeEmotion = 0f;
void UpdateEyeLids(){
float _emotion = (60 * _eyeEmotion);
_leftLid.eulerAngles = new Vector3(0, _emotion, 0);
_rightLid.eulerAngles = new Vector3(0, -_emotion, 0);
}
The problem is trying to mix to two together, simply doing this...
_leftLid.eulerAngles = new Vector3(-_blink, _emotion, 0);
_rightLid.eulerAngles = new Vector3(-_blink, -_emotion, 0);
... does not work; as the axis are now out of place when I change the Range of Close, and Emotion. Blink is no longer on the X axis, and Emotion is no longer on the Y axis.
I believe for it to work, I need the BLINK to occur on the X axis locally, and the EMOTION to occur on the Y axis world.? Maybe...
Answer by Drakon0168 · Dec 09, 2016 at 06:18 AM
You're going to have to make the blink go on both the x and z axis because by changing the y axis you twist the eye messing up the alignment of the x axis to the face, changing the global rotation means the entire eye is going to rotate and it's alignment to the rest of the face is going to change (assuming you don't just have floating eyeballs in which case that would work fine). To use both the x and z axis you are going to have to do some trigonometry to tell how much to turn each axis. Another approach would be to make the eyelids separate objects that are a child of the rest of the eye that way you can change the eyelid's local rotation keeping them aligned with the rest of the eye. In this scenario you would change the eye's y axis rotation and the eyelid's local x axis rotation.
Your answer
Follow this Question
Related Questions
Why is this rotation not performed as expected? 1 Answer
ConfigurableJoint - angular positions (rotation) problem 1 Answer
EulerAngles conversion Quaternion problem 2 Answers
How to add rotation to current rotation over time? 2 Answers
Rotation jumping to a different rotation after rotating a certain amount 0 Answers