Answers for "Trying to tween the rotation of a cube in x and z and having trouble"
http://answers.unity.com/questions/1408138/trying-to-tween-the-rotation-of-a-cube-in-x-and-z.html
The latest answers for the question "Trying to tween the rotation of a cube in x and z and having trouble"Answer by TaylorAnderson
http://answers.unity.com/answers/1408497/view.html
Okay, I've solved this. For whoever reads this thread in the future, you may find this helpful.
Code:
MidiOut.SetInstrument(instrument, channel);
MidiOut.NoteOn(noteIndex, 100, channel.ToInt());
if (lastRotation != null) transform.rotation = lastRotation;
Quaternion rotation;
if (Mathf.Abs(transform.position.x - arm.transform.position.x) > Mathf.Abs(transform.position.z - arm.transform.position.z)) {
if (transform.position.x < arm.transform.position.x) {
rotation = Quaternion.Euler(0, 0, 90);
}
else {
rotation = Quaternion.Euler(0, 0, -90);
}
}
else {
if (transform.position.z < arm.transform.position.z) {
rotation = Quaternion.Euler(-90, 0, 0);
}
else {
rotation = Quaternion.Euler(90, 0, 0);
}
}
rotation *= transform.rotation;
lastRotation = rotation;
transform.DORotateQuaternion(rotation, 0.4f).SetEase(Ease.OutBack);
I've added a few extra things, but the core is essentially the same. What changed was: instead of initially setting rotation to be transform.rotation, and then multiplying it by the rotation I actually wanted, I did it in reverse. I set the rotation variable to the desired rotation, and then at the very end I applied it to transform.rotation.
Doing the multiplication in the reverse order like this has the effect of making the rotation in WORLD space, not LOCAL space, so the object's previous rotation doesn't have an effect on its future rotations.
Thanks to @kryzodoze for sending me in the right direction.Sun, 17 Sep 2017 23:50:34 GMTTaylorAndersonAnswer by kryzodoze
http://answers.unity.com/answers/1408153/view.html
> But it seems like no matter what methods I try, the best case scenario is that it works, but it gets really strange when you rotate one axis and then the other, or rotate the x axis beyond 360 degrees.
If you rotate one axis, rotating another axis will always be relative to the new rotation. Try rotating the x-axis 90 degrees in the editor, and then applying your y or z rotation. Is it what you want? If yes, then you should be fine in the editor.
Rotating beyond 360 degrees should be fine, I believe Unity just mods it with 360 and uses the new value.
Can you explain a little more what exactly you are doing and seeing?Sun, 17 Sep 2017 04:08:54 GMTkryzodoze