Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
3
Question by Hisu · Jun 30, 2015 at 12:12 PM · androidunity 2dtouchlagdisplay

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

Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dlonyar · Jul 02, 2015 at 09:34 AM 0
Share

What's line 21 for?

avatar image Hisu · Jul 04, 2015 at 06:15 PM 0
Share

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 ^^

1 Reply

· Add your reply
  • Sort: 
avatar image
2

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

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Fattie · Jan 26, 2016 at 12:07 PM 0
Share

It's a good tip...

avatar image KaiSD · Mar 02, 2016 at 02:38 PM 0
Share

Thanks! It realy helps.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

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

some android phone's touch won't work sometimes with my game app, but it works perfectly in my phone. 0 Answers

Touch android iput shootting 3 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges