- Home /
My drag camera script gets messed up when changing fingers. Please help! (android)
the following code translates a camera upp and down when draging up and down over the screen. It works but there is one problem, lets say I put one finger down for draging, then I put a second finger down for some other reasson. I now got to fingers touching the screen, the problem is if I release the first finger; the camera jumps quite a bit.
I think the problem lies with the GetMouseButtonDown event, but im not sure how to solve it :/
function Update ()
{
if (Input.GetMouseButtonDown(0) && Input.touchCount == 1)
{
firstTransformPos = (Input.mousePosition.y/Screen.height);
old = 0;
}
if(Input.GetMouseButton(0) && Input.touchCount == 1)// This keeps running while mouse is held down
{
curMousePos = (Input.mousePosition.y/Screen.height) - firstTransformPos;
transform.Translate(0, -(curMousePos-old)*10, 0);
old = curMousePos;
}
}
Does anyone have a solution or perhaps a script which does the same thing basically?
also posted here: http://forum.unity3d.com/threads/132214-My-drag-camera-script-gets-messed-up-when-changing-fingers.-Please-help!?p=892697#post892697
Answer by gregzo · Apr 14, 2012 at 11:37 PM
If you need multitouch, then you need to code specificaly for it, using Input.GetTouch. Might need to raycast with each finger, depending on your use case.
Basic structure:
function Update()
{
for(var i:int=0;i<Input.touchCount;i++)
{
Debug.Log("this finger's id is "+Input.GetTouch(i).fingerId);
Debug.Log("this finger's position is "+Input.GetTouch(i).position);
Debug.Log("this finger's TouchPhase is "+Input.GetTouch(i).phase);
}
}
Your answer
Follow this Question
Related Questions
Android Object Drag With Touch Problem 0 Answers
Touch - drag different objects 1 Answer
Drag and Swap two object using touch 0 Answers
Dragging Camera based on Touch 0 Answers
how create flipping book effect like apple ibook with touch ? 0 Answers