Tell me more ×
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;

        touchPosition.Set(touchDeltaPosition.x, 
                           transform.position.y, 
                           touchDeltaPosition.y);


        // Move object across XY plane
        transform.position = Vector3.Lerp(transform.position,
                                                touchPosition, 
                                                Time.deltaTime*speed);
    }

}
share|improve this question

1 Answer

I think you need to translate screen to world space.

Camera.ScreenToWorldPoint

share|improve this answer

Your Answer

 
discard

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.