- Home /
Question by
fisherman89 · Oct 04, 2016 at 05:11 AM ·
unity 5unity 2dtouch controls
Object follow touch more faster and accurate
I've searched a lot to solve my problem but with no success. The problem is next:
I have a sprite with circle collider and I want to move it under my finger to dodge some other objects. I make it to move buy the problem is that it's moving too slow. Sprite IS FOLLOWING finger but too slow and IS NOT under finger when I move finger fast left-right. My code is:
public class PlayerController : MonoBehaviour {
private Vector3 position;
private bool isTouched;
private RaycastHit2D hit;
void Awake () {
isTouched = false;
}
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update () {
if (Input.touchCount > 0) {
if (Input.GetTouch(0).phase == TouchPhase.Moved) {
hit = Physics2D.Raycast (Camera.main.ScreenToWorldPoint (Input.GetTouch (0).position), Vector2.zero);
if (hit.collider != null && hit.transform.gameObject.tag == "Player") {
isTouched = true;
}
if (isTouched) {
transform.position = Camera.main.ScreenToWorldPoint (new Vector3 (Input.GetTouch (0).position.x, Input.GetTouch (0).position.y, 5));
}
}
if (Input.GetTouch(0).phase == TouchPhase.Ended) {
isTouched = false;
}
}
}
I found same question on this site:
But there is no answer.
Please help!
Comment
Also, I logged only the coordinates of the touch, without rendering object and it's still the same.
Your answer
![](https://koobas.hobune.stream/wayback/20220612093925im_/https://answers.unity.com/themes/thub/images/avi.jpg)