Basically, I am designing a game where I need a canvas image element to respond quickly and move along when it is dragged. So for that, I am implementing IDragHandler interface. But the method OnDrag gets called after a delay of about half second.
public class InputHandler : MonoBehaviour, IDragHandler
{
public void OnDrag(PointerEventData eventData)
{
// this gets logged after about 500 milliseconds
Debug.Log("mouse dragged");
}
}
I've attached this script on the same image element that I want to move along with the drag. This element has raycast target on and the graphic raycast component is enabled for its parent canvas. The image element falls behind the touch point initially but catch up later on because of which it feels like there is some lag in the input. Is there a way to remove/minimize this delay?
The lag might be due to the DragThreshold that is active by default. You can disable it this way:
public class OnDragScript : MonoBehaviour, IDragHandler, IInitializePotentialDragHandler
{
public void OnDrag(PointerEventData ped)
{
transform.Translate(ped.delta);
}
public void OnInitializePotentialDrag(PointerEventData ped)
{
ped.useDragThreshold = false;
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With