Hello everyone !
It’s been 3 days I’m stuck on this problem which should in theory be simple. I’ve tried many different options but without success. I figure a more experienced programmer here might have the elegant solution to this.
Basically I have my camera nested as a child, with a 0f, -0.9f, 0f local position to a parent “rotater” object at the center of the world. That object rotates on X. While to player applies a touch on screen, I’m calculating something like:
float perc = Input.mousePosition.x/Screen.width;
float rotaterXRot = 360f * perc;
rotater.transform.rotation = Quaternion.Euler(new Vector3(rotaterXRot, 0f,0f));
(I do substract the delta of the touch and the actual equivalent on screen X in % of the rotater’s rotation, so when I press the screen the object doesnt “teleport”, and left or right motion will only rotate from the rotation the object is at at the time of the touch.)
It works fine left and right until 90 degrees if I move to the right and 270 if I move to the left. Once I overshoot that 180f around the start position, the rotation jumps to weird values.
My question is, is there any simple way for me to translate my touch.x in % of the screenwidth to rotate my object along a 360f angle where 180f is where the x rotation is at the time of the touch (If when I press my object is currently rotated to -174 degrees on x, this should mark the 180f in my 360f) ?
(here is a graphic to explain more explicitly the situation: