- Home /
Touch movement too slow
Hello,
I have an object I'm moving along the x pane (on android) with the following script
using UnityEngine;
using System.Collections;
public class controls : MonoBehaviour {
void Start () {
}
void Update () {
if (Input.touchCount > 0) {
Touch touch = Input.GetTouch(0);
Vector3 touchPosition = Camera.main.ScreenToWorldPoint(new Vector3(touch.position.x, touch.position.y, 10));
touchPosition.y = transform.position.y;
transform.position = touchPosition;
}
}
}
Currently the object is moving after the finger when the movement speed of the finger is higher. Is there a way I can make the object stay underneath my finger at all times?(so it doesn't look like it's slower then the actualy finger touching the screen)
Check this thread out: http://answers.unity3d.com/questions/733589/unity-touch-controls-accurate-finger-following.html
The linked example is about the mistake of not converting screen pixels to world units, which @Jort is doing correctly from what i can see.
I've experienced the same issue where there's some lagginess when moving objects in Update. Haven't really investigated this since it was never a real problem for me.
You can see this clearly on an Android device when you turn on the touch position markers in the OS debug settings. The OS's markers stay under your finger but objects in Unity lag.
Either it's just that Update doesn't get called often enough (depends on the frame rate setting) or that Unity does some smoothing of the touch position behind the scenes...