- Home /
Unity for Android - Display lag
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.
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)....
EDIT: Any ideas? Despite trying, I can't seem to deal with this problem
So it follows only if my finger is close enough to the object? at least that was the intention. But that's not the problem here ^^
Answer by iaroslav-titov · Jan 26, 2016 at 12:07 PM
Had the same problem, then limited target FPS to 60, and no more lags!
http://docs.unity3d.com/ScriptReference/Application-targetFrameRate.html
Your answer
Follow this Question
Related Questions
How do I prevent / deal with input lag on a touch interface? 3 Answers
Massive Touch Lag on mobile devices? 3 Answers
Camera lagging and flipped 0 Answers
Touch android iput shootting 3 Answers