Rotating Cubes all messed up -- up/down/all around

Hello,

This iOS script is supposed to make a cube rotate on it’s X / Y axis when the user swipes on the screens X / Y axis.

However I’m running into two problems.

  1. -x and -y do not end up being seen by the 2nd part of the script. I see the deltaPosition is negative, but “xMove” and “yMove” on the Cube script remain at 0.

  2. Cubes seem to go in unexpected directions. Sometimes they seem to rotate on the z-axis, which doesn’t make any sense to me.

Code (first part is the controller that takes in the touch input, and runs a function on the cube that’s selected):

if (((Input.GetTouch(0).deltaPosition.y * 2) / 2) > ((Input.GetTouch(0).deltaPosition.x * 2) / 2))
   {
      selectedCube.GetComponent(cubeScript).WasMoved(0, 90 * (Input.GetTouch(0).deltaPosition.y / 100));
   }
   else
   {
      selectedCube.GetComponent(cubeScript).WasMoved(90 * (Input.GetTouch(0).deltaPosition.x / 100), 0);
   }

function WasMoved (xMove : float, yMove : float){
	for (var cube : Collider in neighborCubes)
	{
		cube.gameObject.transform.Rotate(yMove, xMove, 0);
	}
	print ("WasMoved X/Y: " + xMove + " / " + yMove);
}

Any idea where I’m going wrong for either problem?

Rotate by default is relative to the self. I.e. the cube is will rotate around its own Y axis no matter where it is pointing. So what you are seeing as ‘Z’ rotation is really rotation around it own ‘X’ or a ‘Y’ axis on a cube that is already rotated. You might get the results you are looking for if you add the Space.World parameter.

 cube.gameObject.transform.Rotate(yMove, xMove, 0, Space.World);