- Home /
Multitouch physics drag with TargetJoint2D
Hello there! I want to make a mobile game in which you can drag 2D objects simultaneously with two or more fingers. Only one TargetJoint2D per object.
if (Input.touchCount > 0) {
foreach (Touch _touch in Input.touches) {
if (GetComponent<Collider2D>() == Physics2D.OverlapPoint(Camera.main.ScreenToWorldPoint(_touch.position))) {
touchID = _touch.fingerId; // there is an error
tap = true;
}
}
touch = Input.GetTouch(touchID); // touch is target
...some code here...
"tap" means that I touched the box and TargetJoint2D will be updated. It becomes false if I take my finger off the screen.
But there is a bug and I don't know how to fix it. If I touch in this order:
Touch outside the sprite
Touch the sprite
Release outside the sprite
That drag stops working (target and anchor no longer move) and an error occurs: ArgumentException: Index out of bounds.
In the line that I indicated in the code. After touching the box again, everything works again.
Also I need somehow stop react to other touches after touching my blue box once.
I’ve been breaking for two hours without any progress.
Can you give me an advice is there a way to fix it? Sorry for my English and thank you in advance.
Your answer
Follow this Question
Related Questions
Multi touch on mobile game 0 Answers
Jump Force (rigid body velocity) is not equal in different mobile phones 0 Answers
Multiple Cars not working 1 Answer
Android 2D multitouch joystick + buttons 0 Answers
Two player touch screen 1 Answer