Unity for Android - Display lag

647 views Asked by At

I'm new to Unity/Android, so mistake here may be pretty basic. All I have right now is background, and object on it that is following my input (touch) when I move my finger on a screen.

The problem is, it's staying behind, even when I move my finger in a moderately slow pace. In developer settings on my testing device I've turned on option that shows all touches on the screen (white dot). That's why I believe it's only display lag (or error in code), because while white dot is also behind (I've read it's hard to avoid input lag on Android devices) it's much much closer than my object (and I expect them to be in the same place). It almost looks like my object is on a string.

Here is my code:

using UnityEngine;
using System.Collections;
using System;

public class PlayerMovement : MonoBehaviour {

    Vector3 worldCoordinates;

    void Start () {
        Application.targetFrameRate=60;
    }

    void Update () {

        foreach(Touch touch in Input.touches)
        {
            if (touch.phase == TouchPhase.Moved) 
            {
                worldCoordinates = Camera.main.ScreenToWorldPoint(touch.position);

                if ((Math.Sqrt(Math.Pow(worldCoordinates.x,2) + Math.Pow(worldCoordinates.y,2)) - Math.Sqrt(Math.Pow(transform.position.x,2) + Math.Pow(transform.position.y,2))<1))
                {
                    transform.position = new Vector3(worldCoordinates.x,worldCoordinates.y);
                }
            }
        }
    }
}

I've already tried to disable antialiasing. and change target fps to 60, but there was no difference. Maybe there's something wrong with my code (like touchphase.moved happening too late for that kind of functionality) but I haven't found such information.

Will appreciate any input.

EDIT: Has anyone had similar case in their application? All I can find in web is topics about input lag (and it's not the main problem here, only part of it), and even those give no answers. Honestly I'm out of options now and consider changing apllication to something that requires only taps (since taps work fine according to other topics)....

0

There are 0 answers