Well, im new to Unity and touch based events in general. Im trying to make the camera move on the X/Y coordinate plane with touch. I have been able to get it to move, and its moving in the right direction (so I think) but its moving in extreme steps. Im using the cameras beginning position and take the new delta position from it, and updating the camera postion that way. From what I can tell it is moving in the right direction, but its jumping by the thousands per short movement. Ive even tried to multiply the deltaposition by .001 and still no luck. Im pretty sure this is an easy fix. Here is the code
void Update () {
foreach(Touch touch in Input.touches) {
if (touch.phase == TouchPhase.Began) {
if (touch.fingerId == 0) {
//Get starting position of touch
touchBound = touch.fingerId;
ScrollTouchOrigin = touch.position;
}
}
//Unbind the touch if the touch phase ends
if (touch.phase == TouchPhase.Ended) {
touchBound = -1;
ScrollTouchOrigin = Vector2.zero;
}
//Do movement on touchphase move
if (touch.phase == TouchPhase.Moved) {
//Only move if the touch that is bounds is the one that moved
if (touch.fingerId == touchBound) {
//Get current camera postion
Vector3 oldPos = Camera.main.transform.position;
Camera.main.transform.Translate(new Vector3(oldPos.x - (touch.deltaPosition.x * 0.001f), oldPos.y - (touch.deltaPosition.y * 0.001f), 5.0f));
mGuiTextX.text = Camera.main.transform.position.x.ToString();
mGuiTextY.text = Camera.main.transform.position.y.ToString();
}
}
}
}