- Home /
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));
}
}
Answer by StephanK · May 03, 2013 at 12:46 PM
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.
Hi,
Sorry I am new to this, could you explain it or show me how you would write the code, I'm not sure how to include the code you have provided above.
thanks in advance
Your answer
![](https://koobas.hobune.stream/wayback/20220613101447im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Swipe functions for android.? 3 Answers
How can I achive faster response time from Input? 3 Answers
How to launch a Hyperlink on Touching a Game Object ? 0 Answers
How to recreate shape shifters 3d mechanic 0 Answers
Touch input in browsers 0 Answers