Hey, everyone,
I almost have it all! With help from you guys, I have my left and right swipe script working great but I want to move forward and backward on the up and down swipe instead of rotating. I don’t need my players looking at the ceiling or the floor. This is what I have so far:
#pragma strict
private var h : float;
private var v : float;
var horozontalSpeed : float = 1.0;
var verticalSpeed : float = 1.0;
function Update()
{
if (Input.touchCount == 1)
{
var touch : Touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved)
{
h = horozontalSpeed * touch.deltaPosition.x ;
transform.Rotate( 0, -h, 0, Space.World );
v = verticalSpeed * touch.deltaPosition.y ;
transform.Rotate( v, 0, 0, Space.World );
}
}
}
I want to change the “v = verticalSpeed * touch.deltaPosition.x; transform.Rotate( v, 0, 0, Space.World );” line from rotating the player to moving him forward and backward. So, when you swipe left and right, the player turns left and right but when you swipe up and down, the player moves forward and backward. I thought it was a deltaPosition.z but that didn’t work for me when I tried it. I looked around but all I can find is information about rotation and not forward and backward movement.
Any help fixing my javascript would be greatly appreciated.
Thanks so much!
Tom