- Home /
Question by
tuhinbhatt · Feb 11, 2013 at 03:40 PM ·
transforminputpositiontouch
Drag+an+object+to+touch+position(Problem)
Hello i am using the below code to move the gameobject to the screen touch position.
using UnityEngine;
using System.Collections;
public class dragtheobjectontouch : MonoBehaviour {
public GUIText debugtext;
public GameObject dragobject;
public Vector2 realworldposition;
void Awake()
{
Application.targetFrameRate=60;
}
void Update () {
if(Input.touchCount>0)
{
foreach(Touch touch in Input.touches)
{
if(touch.phase==TouchPhase.Moved)
{
debugtext.text=touch.position.ToString();
realworldposition=Camera.main.ScreenToWorldPoint(touch.position);
dragobject.transform.position=new Vector3(realworldposition.x,realworldposition.y,dragobject.transform.position.z);
}
}
}
}
}
The Code works perfectly and the object follows(moves) to position of the touch. But when i quickly move my finger on the touchscreen(ipad) the object lags behind the finger. Of course it reaches the actual position of the touch if i slow down the movement of my finger. This problem doesnot occur if i move my finger slowly on the screen. Can anybody help me on this .?
Comment
Sorry i double posted this question i think hope moderator has rejected the same question, i didnot notice it was pending approval by moderator so reposted it again(thought i made some mistake in posting it). Sorry for that.