Question by
Ceroy · Apr 18, 2019 at 12:54 PM ·
gameobjecttouchrigidbody2dtouchscreen
How to make GameObject follow with finger without delay?
Hi So I have been trying to make my 2D player follow touch location and I have been using the below script.
void Update()
{
if (Input.touchCount > 0)
{
Touch touch = Input.GetTouch(0);
touchPosition = Camera.main.ScreenToWorldPoint(touch.position);
direction = touchPosition - transform.position;
rb.velocity = new Vector2(direction.x, direction.y) * moveSpeed;
if (touch.phase == TouchPhase.Ended)
rb.velocity = Vector2.zero;
}
}
But the problem is, the gameobject is not moving exactly with the touch and is rather just following it . And increasing the moveSpeed variable doesn't help. Please help me with a solution to make the Player object move exactly under the finger.
Comment
Your answer
Follow this Question
Related Questions
Rotate Rigidbody2D by Touch 1 Answer
How do you register single touches and prevent players from holding down on screen? 0 Answers
Perspective camera touch movement 2 Answers
Separate Input from Touch on GUI 0 Answers
Android Touch Issue 1 Answer