- Home /
Other
(UNSOLVED) Touch.deltaPosition on two fingers??How??
Hi, i have been messing with this for a while not but i couldn't figure out how to do it.. What i have been trying to do is get an output of two independent fingers deltaPosition.Here is the code i was trying to get it from. All of the help is appreciated.Thank you.
function Update () {
for (var touch : Touch in Input.touches) {
if (touch.fingerId == 1) {
delta1 = Input.touches [0].deltaPosition;
}
if (touch.fingerId == 2) {
delta2 = Input.touches [1].deltaPosition;
}
}
}
Answer by Sparrowfc · Nov 19, 2013 at 06:55 AM
int touchID1 = -1;
int touchID2 = -1;
float deltaPos1, deltaPos2;
void Update()
{
//first, record actived touchID
foreach(Touch t in Input.touches)
{
if(t.phase == TouchPhase.Began)
{
if(touchID1 == -1)
touchID1 = t.touchID;
else if(touchID2 == -1)
touchID2 = t.touchID;
}
else if(t.phase == TouchPhase.Ended || t.phase == TouchPhase.Canceled)
{
if(t.touchID == touchID1)
touchID1 = -1;
else if(t.touchID == touchID2)
touchID2 = -1;
}
}
//second, track the touch
foreach(Touch t in Input.touches)
{
if(t.touchID == touchID1)
{
deltaPos1 == t.deltaposition;
}
else if(t.touchID == touchID2)
{
deltaPos2 == t.deltaposition;
}
}
}
Basically you could do the second part in the same for loop as the first, just check for TouchPhase.$$anonymous$$oved and the id-s you are looking for.
didn't work! I still get the delta positions of two finger when one of them stationary.When both of the finger moves only one delta value is shown! $$anonymous$$Y GOOOOOOOD!!!!
$$anonymous$$aybe your device doesn't fully support mul$$anonymous$$ch? I have a nexus 7 (the old one) and i can have 10 simultanous touches without any problems. You can try my $$anonymous$$obileStats app(android only) and see if they work.
$$anonymous$$ay i ask how you "show" the deltas?
Thank you for the app i'll try it now. $$anonymous$$y phone is samsung s3 $$anonymous$$i and the programs inside of it shows that multi touch is supported.I use guitexts to write down the delta values to screen.The problem is i can get the positions of each finger on the screen simultanous ly but cannot get the deltaPositions.You see that there are two variables delta1 and delta2 and they represent their touch.deltaPosition. When i write touch.position i can get the positions of them simultanously.I think there is sth wrong with that ".deltaPosition" code inside unity3d.
Hi man it doesn't work as well as in your apk.I see that when i put 2 of my fingers simultanously only the last finger's deltaPos is shown and other one is zero?? But i can drag multiple cubes at the same time? if you havent done it with deltaPosition to move them around how did you?
Answer by Essential · Nov 04, 2013 at 12:36 AM
Try this:
function Update ()
{
for (var touch : Touch in Input.touches)
{
if (touch.fingerId == 0)
delta1 = touch.deltaPosition;
else if (touch.fingerId == 1)
delta2 = touch.deltaPosition;
}
}
Hey, thank you for the reply but nothing is changed.Well actually the code above is no differente than i did though.
What i want to achieve is that when i put two of my finger on the screen and when i move two of my fingers at the same time independently,i want to know each finger's deltaPosition in realtime when i move my fingers simultaneously.Could someone give me a hand on this or point me out a way of doing it? Thanks
Tell me what you want to do. Why are you trying to get the deltas of two fingers?
If you want the delta of each finger then you have already done that. $$anonymous$$aybe you want the delta of the point between the fingers ? And then when you move your fingers, the middle point will also move and you want to get the delta of the middle point.