0
\$\begingroup\$

I rotate a 3D object to left and right with swipe to left and right. Problem is on different devices with different pixel densities, it gets faster and slower. i.e. if you move your finger 1 cmm on one device will not rotate the object same amount that it will on another device, like a Retina and non-Retina one.

Last time I wanted to solve this I could not as IIRC there was no way to get physical pixel density of device or it's dimensions (to get density via division over resolution)

Thanks.

\$\endgroup\$
1
\$\begingroup\$

Presumably, using Screen.width and Screen.height should do the trick. Then you just divide the delta in dragged pixels by that total screen dimension, and this will give you some fraction between 0.0 and 1.0. You can multiply that by some fixed angle (and possibly Time.timeDelta?) to get your rotational increment.

\$\endgroup\$
0
\$\begingroup\$

use viewport coordinates and detect swipes based on percentage of the screen https://docs.unity3d.com/ScriptReference/Camera.WorldToViewportPoint.html

const float dragThreshold = 0.15f;
Vector3.Length(cam.WorldToViewportPoint(endDrag) - cam.WorldToViewportPoint(endDrag)) > dragThreshold
\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.