Unity Input.touches inverted Android Game

Hi,

I am creating a 2D Android game and all I’m trying to do is drag an object with my finger, I have the object moving when I move my finger across the screen but it’s inverted, it moves away from my finger, any ideas please?

var speed = 5.0;

function Update () {

if (Input.touches[0].phase == TouchPhase.Moved)
{

var y = Input.touches[-0].deltaPosition.y *speed* Time.deltaTime;
var x = Input.touches[-0].deltaPosition.x *speed* Time.deltaTime;

transform.Translate( new Vector3(x, 0 , y));
}
}

transform.Translate uses your objects local coordinate system per default. If you want to move something in “world” space use

transform.Translate(translation,Space.World)

Or don’t rotate your object then world and local coordinate system is the same.

Also to drag an object with your finger it is better to use the actual position of the touch and set the object to that exact position rather than relying on any delta calculations.