- Home /
The question is answered, right answer was accepted
Mobile touch dragging from mouse dragging
Hi.So i have this function made to drag an object by the mouse and i want it to do the same with touch.Can you guys help?
void Dragging ()
{
Vector3 mouseWorldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
Vector2 catapultToMouse = mouseWorldPoint - catapult.position;
if (catapultToMouse.sqrMagnitude > maxStretchSqr) {
rayToMouse.direction = catapultToMouse;
mouseWorldPoint = rayToMouse.GetPoint(maxStretch);
}
mouseWorldPoint.z = 0f;
transform.position = mouseWorldPoint;
}
Answer by HarshadK · Sep 22, 2014 at 06:27 AM
Everything you need is here at Touch.
In your current code all you need to do is Instead of Input.mousePosition you use Touch.position.
So it is like, instead of:
Vector3 mouseWorldPoint = Camera.main.ScreenToWorldPoint(Input.mousePosition);
it becomes:
Vector3 mouseWorldPoint = Camera.main.ScreenToWorldPoint(touch.position);
Also you can handle touch being moved on screen using TouchPhase.Moved.
it does not let me set Touch.position is Input.GetTouch(0).deltaPosition good?
problem solved with Input.GetTouch(0).position thank you
Follow this Question
Related Questions
Dragging UI Image by touch 3 Answers
How Can I Drag the Object With Touch ? (Mobile) 4 Answers
Multitouch drag object 0 Answers
Emulating screen touch on devices 1 Answer
Drag and Swap two object using touch 0 Answers