[Trackball] Rotation around 2 axis

Hi,

I’m trying to simulate a trackball by allowing a sphere to rotate around the x and y axis. I did a small piece of code to make my sphere rotate along those 2 axis simultaneously :

void Update () 
		
	{   
		prevAngle.x += 5;
		prevAngle.y += 5;

		transform.eulerAngles = new Vector3(prevAngle.x%360,prevAngle.y%360,0);
}

I was expected my sphere to rotate in “diagonal” but it is not the case - the movement is very weird.

I modified a bit the previous code in order to rotate only along the x axis and I was surprised to notice via the inspector that the x rotation value is not the only one to be update, sometimes the y and z values jump to 180 and then back to 0.

I do want the x and y rotation values to be the only one to be modified and I want to be able to compare between two updates the delta angle for the x and y axis.

I tried to use the Quaternion classes with the eulerAngles but I got a new problem, the x value freeze at 90 - cannot understand why.

So how can I make my sphere rotate along the X and Y axis and be able to calculate the delta angle for each axis ?

Thank you

Have you tried this?

Yes I did. The problem is the same, when you Rotate only along the x axis the y and z angle values are set to 180 for a short times. It seems that this modification occur when the x angle is equal to 360.