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.
-
-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.
-
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?