I'm trying to make a game where you control a character via touch on Android devices.
The player will have two degrees of movement.
When you touch the touch screen and move your finger, the game object should move to your finger's location and follow your finger as you move it.
Here is an example of what I'm trying to do: http://www.youtube.com/watch?v=OoqRC8QptzM#t=01m01s (@ 1:02).
I already know I need to use Input.touches.
I've tried using Transform.translate and Vector3.Lerp, neither gave me the results I wanted.
Here is some of the code I've tried using:
#pragma strict
var speed : float = 1;
function Start () {
}
function Update () {
if (Input.touchCount > 0 &&
Input.GetTouch(0).phase == TouchPhase.Moved) {
// Get movement of the finger since last frame
var touchDeltaPosition:Vector2 = Input.GetTouch(0).deltaPosition;
var touchPosition:Vector3;
touchPosition.Set(touchDeltaPosition.x,
transform.position.y,
touchDeltaPosition.y);
// Move object across XY plane
transform.position = Vector3.Lerp(transform.position,
touchPosition,
Time.deltaTime*speed);
}
}