I’m making an app with touch input to rotate and pan an object on the screen. I’m basically getting vector2 of the displacement of a touch point every frame, and rotating the object accordingly.
My problem is that devices with high res screens end up rotating a lot more than ones with lower resolutions due to the touch displacing more pixels across the screen.
What is a good way to normalize the movement between all devices? The scaling methods I’ve used are not working as well as I want across multiple devices.
Did some more testing. The issues seems to be from Unity Remote having different sensitivity than when I’m running a built app, even with the resolution for Unity Remote set to Full. I’m not sure why the inputs are different for Unity Remote vs built.
I didn’t use Unity Remote for many years due to bugs.
Provide your code to get qualified support from the community.
Code is below. The problem has been solved, though.
Something to do with the time.deltaTime differences between the editor vs. on-device. I just scaled the speed accordingly.
private Vector2 TouchScaler(Vector2 _input)
{
return new Vector2(_input.x , _input.y) / Screen.height;
}
private float GetZoomMultiplier() //used to adjust the speed of pan and rotate based on zoom.
{
return (Camera.main.fieldOfView/zoomLimit[1]);
}
private void TouchRotate()
{
if (noRot)
return;
if (Input.touchCount == 1)
{
Touch touch = Input.GetTouch(0);
if (IsPointerOverUIObject())
return;
if (touch.phase == TouchPhase.Began)
{
startPos = touch.position;
isTouching = true;
}
else if (touch.phase == TouchPhase.Moved)
{
if (isTouching)
{
currentPos = touch.position;
Vector2 direction = (currentPos - startPos);
Vector3 currentTilt = tiltAxis.transform.localEulerAngles;
currentTilt.x = (currentTilt.x > 180f) ? currentTilt.x - 360f : currentTilt.x;
float rotX = TouchScaler(direction).y * touchSpeed * GetZoomMultiplier() * Time.deltaTime;
currentTilt = new Vector3(currentTilt.x + rotX, 0, 0);
currentTilt.x = Mathf.Clamp(currentTilt.x, tiltLimit[0], tiltLimit[1]);
tiltAxis.transform.localEulerAngles = currentTilt;
Vector3 currentRot = rotAxis.transform.localEulerAngles;
float rotY = currentRot.y - TouchScaler(direction).x * touchSpeed * GetZoomMultiplier() * Time.deltaTime;
currentRot = new Vector3(0, rotY, 0);
rotAxis.transform.localEulerAngles = currentRot;
startPos = currentPos;
UpdateRotationText();
}
}
else if (touch.phase == TouchPhase.Canceled || touch.phase == TouchPhase.Ended)
{
isTouching = false;
}
}
}