Drag by touch issue "lag"

Hi all,

I use this code to move a object on the screen where my finger is moving.
It is working but it’s slow “lag”.
When I move my finger slowly on the screen its following but when you go just a little faster it stops following and I have to go back to the object to reselect it and start moving again.

Is there a way to do this better? :slight_smile:

Roy

function Update () {

    for (var touch : Touch in Input.touches){

        var ray = Camera.main.ScreenPointToRay(touch.position);

        var hit : RaycastHit;

        if (Physics.Raycast (ray, hit, 100)) {

            if(touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) {

                var cameraTransform = Camera.main.transform.InverseTransformPoint(0, 0, 0);

                object.transform.position = Camera.main.ScreenToWorldPoint(new Vector3 (touch.position.x, touch.position.y, cameraTransform.z - 0.5));

            }

        }

    }
}

Bump! :wink:

As far as I know, it’s a hardware/OS limitation.

Try function FixedUpdate instead.

I know this is old, but one thing I found was to include the touch . phase == stationary in your checking of which phases to do something. I have found not doing this causes the object to stutter and drop, most likely when the user’s finger pauses.

Unknown identifier : ‘object’