smooth on touch 360° rotation

Hi, I am trying to rotate a cube with this script. In editor it acts as I would expect, but on Android device, the rotation is not that smooth, the cube is being rotated on every touch on screen in such way, I can’t really work with it.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class rotateCube : MonoBehaviour
{
    Vector3 mPrevPos = Vector3.zero;
    Vector3 mPosDelta = Vector3.zero;

    void Update() {

        mPosDelta = Input.mousePosition - mPrevPos;
        bool interacted = false;
        if (!Input.touchSupported)
        {
            interacted = Input.GetMouseButton(0);
        }
        else
        {
            interacted = (Input.touchCount == 1);
        }
       
        if(interacted)
        {
            if(Vector3.Dot(transform.up, Vector3.up) >=0)
            {
                transform.Rotate(transform.up, -Vector3.Dot(mPosDelta, Camera.main.transform.right), Space.World);

            }
            else
            {
                transform.Rotate(transform.up, Vector3.Dot(mPosDelta, Camera.main.transform.right), Space.World);
            }

            transform.Rotate(Camera.main.transform.right, Vector3.Dot(mPosDelta, Camera.main.transform.up), Space.World);
        }

        mPrevPos = Input.mousePosition;
    }
}

well, if it’s a multitouch screen, this line

interacted = (Input.touchCount == 1);

will block any rotation if you have two or more registered touches.

this might be the sole reason for this behaviour, depending on the actual accuracy of the capacitive sensor, and the ability of the phone’s software to actually interpret single touches as being exactly single. it is likely jittering because of this, because sometimes you have 1 sometimes 2 or more blobs interpreted as individual touches, but your code reacts to it discreetly.

maybe this has nothing to do with it, and I’m exaggerating, but if you want to be sure, try to set that check to

interacted = (Input.touchCount >= 1);

let me know if it works the same, and it would especially help to report back whether this behavior is erratic or skipping frames/touches in regular intervals.

You need also deltaTime in our rotation…