Search Unity

Object Flickers When Being Dragged

Discussion in 'Editor & General Support' started by Annundur, Apr 15, 2019.

  1. Annundur

    Annundur

    Joined:
    Dec 18, 2018
    Posts:
    12
    Hello everyone. I'm developing a 2D card game for Android, in which the user has to swipe left or right the cards as part of the gameplay. The problem is that, while dragging, the object (the card itself) flickers constantly, like if it was trying to get back to where it was.

    The problem doesn't happen at all when I run the project inside Unity, but it happens always when played in any Android device (tested on three different devices). My game isn't too big, so I don't think this is a performance issue. I had a longer code before, calculating more stuff as the player swipes, but I've erased almost all of it, narrowing it down to just a few lines of movement, but the problem still happens.

    Code (CSharp):
    1. void OnMouseDrag(){
    2.         newPosition = (startPosObjectX + (Input.mousePosition.x - startPosMouseX)) / 108f;
    3.         transform.position = new Vector3 (newPosition , transform.position.y, transform.position.z);
    4. }
    My intention is to move the card relative to how much the user has moved the finger since he/she started dragging.

    I had some problems with ScreenToWorldPoint, that's why I divide everything between 108. It's a temporary solution that gives me a reasonable ratio of movement. I've tried changing the camera from Orthographic to Perspective, as well as any idea that came up to my mind, but nothing worked. And the code now is so simple, that I really don't know what's wrong. I've searched the forum for dragging problems but I couldn't find anything like this.

    I've uploaded a short video recorded from my phone, that shows me slowly dragging the card and exactly the type of flickering I'm talking about:
    https://www.dropbox.com/s/4gnromhb0pe1ve4/UnityFlicker.mp4?dl=0

    Any help would be greatly appreciated.
    Thank you very much!