Cubes rotating the wrong direction when camera is facing the opposite Way. (Webplayer Preview for example)

Here is the webplayer preview. Right-Click drag moves the camera, left click drag on a cube rotates the cube. http://www.sfbaystudios.com/cubetest.html

The problem is that once the camera is facing a different direction from the start, the cubes do not rotate properly – they rotate backwards or sometimes on a completely different axis than I expect. I pass the following info to the cube script:

selectedCube.GetComponent(cubeScript).WasMoved(90 * (rawXDelta / 100), 90 * (rawYDelta / 100));

(rawXDelta / rawYDelta is the change in position of the mouse between frames).

function WasMoved (xMove : float, yMove : float){
	var i = 0;
	for (var cube : Collider in neighborCubes)
	{
		if (yMove * yMove > xMove * xMove)
		{
			cube.gameObject.transform.Rotate(yMove, 0, 0, Space.World);
		}
		else
		{
			cube.gameObject.transform.Rotate(0, -xMove, 0, Space.World);
		}
	}
}

I’m guessing that I need a way to change the axis used here: cube.gameObject.transform.Rotate(yMove, 0, 0, Space.World); – so that it’s either a negative or a different axis based on where the camera is facing. However, I’m having a headache of a time trying to figure out how to do that. Any suggestions?

rotate around the cameras axes not your own.

probably easiest to rotate(Ymove * axis, space.world)

axis = camera.main.transform.transformdirection(transform.right);

that however will rotate stuff at an angle if you want really just to rotate up and down only and not at an angle if your at an angle you’ll have to use the normal of the facing of the object under the cursor.

Cast a ray to the object and rotate based on the normal.