Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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;


        // Move object across XY plane
        transform.position = Vector3.Lerp(transform.position,

share|improve this question

2 Answers 2

up vote 2 down vote accepted

I think you need to translate screen to world space.


share|improve this answer

I imagine you're working with an ortographic camera. With them, the position of the elements work with the X and Y elements defining the position on screen and the Z element defining its depth.

Check this link on how to use DeltaPosition: Input.GetTouch

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.