Hello everyone,
First of all, I’m really sorry to post about this because I know and I have read that it has been asked numerous times, yet I have been trying really hard to find the answer and understand the codes but I think I’m way too deep in confusion in my own code to be able to think properly so…Please allow me to re-ask the question here.
I am developing an application where you can observe a cultural object, turn around, zoom etc. As the rotation of the object itself was really crappy, I decided to parent it to an empty which itself would be dedicated to the rotation. That empty is located at the center of the object, and when it rotates, the camera rotates with it. For the zoom, I have created another empty within the first one, and I can zoom my camera by scaling the empty.
Ok that’s for the basic setup of my scene. In order to be able to drag on a phone, I have created an event, and a public void OnDrag. Like this (in short, I have cut some parts of code):
public void OnDrag(PointerEventData drag) {
if (Input.touchCount == 1) {
if (rotateOrTranslate == DragState.rotate || rotateOrTranslate == DragState.neutre) {
empty_rotation_Tgt.Rotate (-drag.delta.y * speed * Time.deltaTime, drag.delta.x * speed * Time.deltaTime, 0, Space.Self);
NewClic = 0f;
FormerClic = 0f;
}
So basically, it rotates according to the direction of the finger dragging. The condition you can see rotateOrTranslate == DragState.rotate is in order to determine if the user wants to pan or rotate but that’s another problem.
It seems that the problem of flipping occurs when the rotation of the empty is on approximatively 89 and 270. Whereas if I turn only on the Y axis, I can do a 360° without any problem.
So I have tried a lot of things. First I have tried to separate the rotation on Y and X by creating two separate emptys, and then clamping the rotation of X. Yet in that case, when you drag on one axis and then try to drag on another axis without letting go of the mouse (or the drag), the rotation makes crappy stuff. So I have tried putting a condition that says “if the X rotation is over that value, don’t rotate anymore and lock X on that value”, but it doesn’t work either.
I’m thinking this might have something to do with eulerAngles and Quaternions, but I’m really not at ease at all with these questions so I need help to understand.
Do you guys have an idea how I can get the hell ouf of this mess lol?
Thank you so much
Popi
PS: two pictures to show you the problem