# Newbie to iPhone dev, coco touch questions

I want to do a small test with a 3d cube , texture map and the ability to touch the cube and move it based upon rotation…

from previous unity coding

``````var speed = 5.0;
function Update () {
var x = Input.GetAxis("Horizontal") * Time.deltaTime * speed;
var z = Input.GetAxis("Vertical") * Time.deltaTime * speed;
transform.Rotate(x, 0, z);

}
``````

So if anyone could point me in the right direction, I think I have to cast a ray out and then do the transform… any small tutorial like this around?

Hmm, do you actually want to “touch” the cube, if so have a look at: iPhoneTouch.position, and raycast to the cube, on the other hand, if you’re just looking to rotate the cube via screen touch, here’s how I do it:

``````for (var event : iPhoneTouch in iPhoneInput.touches) {
// to detect a swipe for camera movement
if(event.phase == iPhoneTouchPhase.Moved) {
// alter camera position
// use direct method calls so that cameras can apply unique constraints based on view intended
normalizedX = event.deltaPosition.x / Screen.width;

gameCameraController.Move(new Vector3(normalizedX, 0, 0)); // 100 times faster than send message!!!!

}// end swipe
} // end for events
``````

NOTE: move is implemented in C# not javascript as above:

``````public void Move (Vector3 move) {
if(firstPassMove) {
setOrientation = true;
firstPassMove = false;
firstPassAcc = true;
}
// set to current rotation - will change constantly
if(setOrientation) {
originalRotation = transform.localRotation;
setOrientation = false;
}
// Read the mouse input axis
rotationX += move.x * sensitivityX;
rotationY += move.y * sensitivityY;

rotationX = ClampAngle (rotationX, minimumX, maximumX);
rotationY = ClampAngle (rotationY, minimumY, maximumY);

Quaternion xQuaternion = Quaternion.AngleAxis (rotationX, Vector3.up);
Quaternion yQuaternion = Quaternion.AngleAxis (rotationY, Vector3.left);

transform.localRotation = originalRotation * xQuaternion * yQuaternion;
}
``````

Hope this helps,

Galen

thanks that helps, any idea how to maybe if I have 3 cubes on the screen and I touch to select one that it shows some sort of flash outline (material trick) so it shows the user what is the highlighted and active object to move around?

Just played with Unity 3 a bit, seems like all iPhone version is all merged into one now.