Multitouch beginner problems

Hello,

I’ve been searching the forum for an answer to my multitouch issue, but unfortuantely haven’t been very lucky so far.

I guess it’s either a basic thinggy or I’m completely off road :wink:

Alright, my scene basically contains 3 objects. Let’s call them BoxA, BoxB and BoxC. Now, each object has its own script, handeling touch input data. In order to keep things simple, lets say, I want to rotate these boxes, when touching them.

So, what happens now is this. I can perfectly touch and rotate each Box individually, but as soon as I try to rotate BoxA and BoxB at the same time, things stop to work. I do understand, that this requires multitouch to be enabled and that’s what I did. On top of each script, I put:

static var multiTouchEnabled = true;

I already have a feeling, that this is not enough and I kinda sense, that I might have to handle all multitouch input from within a single script. Is that right?

Let me share the script with you, that is in BoxA, B and C:

function Update () {
	for (var touch : iPhoneTouch in iPhoneInput.touches) { 
		 if (touch.phase == iPhoneTouchPhase.Moved) {
			if (collider.Raycast (ray, hit, 100)) { 
				var touchDeltaPosition:Vector2 = iPhoneInput.GetTouch(0).deltaPosition;
				
				transform.Rotate (0,touchDeltaPosition.x,0);
				
      		}
		}
	}
}

I guess my mistake was to believe, that the device would process all the touchinput data for every script individually. In other words: If I have 2 scripts and both contain touch methods, it would automatically execute them when needed. Even if that meant, running 2 scripts simultaenously.

Any help appreciated. Thanks in advance

Hello!

The problem is that if you touch with 2 fingers, the other finger will be stored in the 2nd position of the touch array, that might be your problem :slight_smile:

Thanks for the hint.

I read something about touch(0) and touch(1). However, not entirely sure how I could pull this off. I’ll play with it a bit. If you have suggestions on how to change the code and don’t mind sharing, I’d definitely appreciate it.

Thanks.

I don’t know enough about multitouch yet, but it looks like the bit that checks all the fingers is fine… but when it comes to the rotating bit with touchDeltaPosition, you’re always using the movement data from finger 0, rather than the finger you are currently checking in your for loop.

Instead of:

var touchDeltaPosition:Vector2 = iPhoneInput.GetTouch(0).deltaPosition;

try use:

var touchDeltaPosition:Vector2 = touch.deltaPosition;

…maybe?

Hi there,
Did you figure out a solution for this?
I’m running into the same issue, I almost figured it out but not quite :frowning:
I modified your code a little to try to isolate the touches using touch id.

static var multiTouchEnabled = true; 
var GUICameraGameobject : GameObject;
var GUICamera : Camera;
var hit1 : RaycastHit;
var FingerId : int = 0;

function Start(){
	GUICameraGameobject = GameObject.Find("Main Camera");
	GUICamera = GUICameraGameobject.GetComponent (Camera) as Camera;	
}

function Update () {
   for (var touch : iPhoneTouch in iPhoneInput.touches) {
   	   FingerId = touch.fingerId;
       if (touch.phase == iPhoneTouchPhase.Moved) {
         var ray = GUICamera.ScreenPointToRay (touch.position);
         if (collider.Raycast (ray, hit1, 100)) {
            var touchDeltaPosition:Vector2 = iPhoneInput.GetTouch(FingerId).deltaPosition;
            transform.Rotate (0,-touchDeltaPosition.x,0);
            print (touch.fingerId);
            }
      }
   }
}

But one of the touches still effects the other sometimes and i occasionally get this error -

UnityException: Index out of bounds.
UnityEngine.iPhoneInput.GetTouch (Int32 index) (at /Users/build/builds/unity-iphone/iphone/Runtime/Export/Generated/iPhoneInput.cs:94)
Multi Touch 1.Update () (at Assets/Scripts/Test/Multi Touch 1.js:17)

200813–7411–$multitouch_460.unitypackage (5.88 KB)