I’ve been building my own solution for panning and scaling with two fingers, but I’ve noticed something when looking at example codes, like this one from Unity’s tutorials. Many of them update the scale or position of the camera based on the change in finger locations between the current frame and the previous frame. Why don’t they compare the finger locations to their initial position instead, that way they don’t have to update extra variables each frame?
So I tried to implement this sort of solution, using the difference between the current frame positions and the initial positions of the fingers, but discovered that the scale and position become twitchy and jittery. Can anyone explain this behavior to me?
You should show your code. One factor could be, that you need to consider variable deltaTime between each frame. This becomes easy when scaling from frame to frame, because then you just multiply by Time.deltaTime. But better show us your implementation first.
1 Like
Unfortunately I have continued to update my code to work around that problem, so I don’t have example code per se, but I’m still curious about why this would happen. But this pseudocode should give you the gist of it:
//in Update function
if (Input.GetTouch(0).phase == TouchPhase.Began)
{
//Get finger position and camera position
}
if (Input.GetTouch(0).phase == TouchPhase.Moved)
{
//camera position = initial camera position + cam.ScreenToViewportPoint(finger position - initial finger position)
}