Hi, I have really low experience with unity, and I’ve been looking everywhere for a solution to this.
How do I make a 2d object move relative to the finger, in smooth and natural way? It sounds like a relatively simple thing to code for me, but I just haven’t gotten it right yet.
I’ve tried my own methods, which were quite bad, and right now I’m using one I found on an old thread over here:
if (Input.touchCount == 1)
{
Touch touch = Input.GetTouch(0);
if (touch.phase == TouchPhase.Moved && gameStarted)
{
transform.Translate(touch.deltaPosition.x/Screen.width * velocityConstant, 0.0f, 0.0f);
transform.position = new Vector2(Mathf.Clamp(transform.position.x, leftLimit, rightLimit), transform.position.y);
}
}
It gets the job done sometimes, but it’s so inconsistent and unpredictable, it really blows the experience of the game I’m trying to make. Sometimes it moves just a small distance, and then the opposite. My first guess was that it was a framerate problem, but FixedUpdate didn’t solve it.
Is there anything in particular I could change to this code to make the movement solid and consistent? Please help!
Your help will be greatly appreciated, Thank you!