- Home /
 
Iphone top down view touch drag control on Z axis?
Hi,
I am very new to scripting and am trying to building a game where i can control the movement of a ball using the iphone touch screen, the game is a top down perspective game.
i have the following code in javascript that i have been trying to modify so that i can make the ball roll on the z axis, but i am not getting anywhere with it.
var speed = 5.0;
function Update () {
   if (Input.touches.Length > 0)
   {
     if (Input.touches[0].phase == TouchPhase.Moved)
     {
       var x = Input.touches[0].deltaPosition.x *speed* Time.deltaTime;
       var y = Input.touches[0].deltaPosition.y *speed* Time.deltaTime;
       transform.Translate(new Vector3(x, y, 0));
     }
   }
 }
 
                
               After a lot of searching i found out that deltaPosition is a Vector2 and will only work on x and y axis.
Still looking around i have not been able to find any code or information (that i can understand) that will allow me to move the ball on the z axis via touch in a top down perspective.
any help would be greatly appreciated.
Thanks.
Answer by Peter G · Jul 16, 2011 at 01:52 PM
You can change the axises of movement.
 var speed = 5.0;
 
 function Update () {
 
   if (Input.touches.Length > 0)
   {
 
     if (Input.touches[0].phase == TouchPhase.Moved)
     {
       var x = Input.touches[0].deltaPosition.x *speed* Time.deltaTime;
       var y = Input.touches[0].deltaPosition.y *speed* Time.deltaTime;
 
       transform.Translate( new Vector3(x, 0 , y) );
     }
   }
 }
 
              Your answer