I’m using touch input to drag the camera around on the x-y plane. For some reason, the camera’s movement is much slower on Android than it is on iOS. I get similar results on iPhone, iPad, and the Unity Editor, but the panning is slow on Android. I’m simply using pixel measurements and dividing by the screen height, so screen size should not matter (and does not matter on iOS). I’m using Easy Touch for input.
gesture.deltaPosition is a Vector2 in pixels that stores the change in position since the last frame. On_TouchDown is called every frame that the player is touching the screen.
Here’s the code:
void On_TouchDown(Gesture gesture)
{
if (gesture.deltaPosition.magnitude > 0)
{
Vector2 deltaPosition = -1f * panSpeed * (gesture.deltaPosition / (float)Screen.height);
transform.position = new Vector3(
transform.position.x + deltaPosition.x,
transform.position.y + deltaPosition.y,
transform.position.z);
}
}
Of course they are different. The same stroke across the same percentage of screen will return very different number of pixels, and you code moves things based on pixels. You need to standardize. You can base it on Screen.dpi, or you could use the ratio of some base vertical height to the height of the device. Given my guess at how you are using this code, the best solution would be to base it on world units traveled at the distance the object is from the camera.
It looks like this was an Android-specific bug in the Easy Touch plugin (version 2.5). Instead of using their deltaPosition, I calculated my own by using their touch position and comparing it to the previous touch position.
Here’s the working code:
Vector2 previousTouchPosition = Vector2.zero;
//called once when the touch starts
void On_TouchStart(Gesture gesture)
{
previousTouchPosition = gesture.position;
}
//called every frame while touching
void On_TouchDown(Gesture gesture)
{
if (gesture.deltaPosition.magnitude > 0)
{
Vector2 deltaPosition = -1f * panSpeed * ((gesture.position - previousTouchPosition) / (float)Screen.height);
previousTouchPosition = gesture.position;
transform.position = new Vector3(
transform.position.x + deltaPosition.x,
transform.position.y + deltaPosition.y,
transform.position.z);
}
}