0
\$\begingroup\$

My Code is As Followed:

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

public class Sphere : MonoBehaviour

{
    [SerializeField]
    private Touch touch;
    private float speedModifier;
    // Start is called before the first frame update
    void Start()
    {
        speedModifier = 0.01f;
    }

    // Update is called once per frame
    void Update()

    {
        if (Input.touchCount > 0)
        {
            touch = Input.GetTouch(0);

            if (touch.phase == TouchPhase.Moved)
            {
                transform.position = new Vector3(
                    transform.position.x + touch.deltaPosition.x * speedModifier,
                    transform.position.y,
                    transform.position.z + touch.deltaPosition.y * speedModifier);
            }
        }

    }
}

I tried with this code but object is not even responding

\$\endgroup\$
  • 1
    \$\begingroup\$ Did you try increasing your speedModifier? You can also put a : Debug.Log(yourmovementvector); where you moving the object, to see if it even gets called. \$\endgroup\$ – formatc2013 Oct 16 at 8:46
  • \$\begingroup\$ According to the docs touch.deltaPosition is: The position delta since last change in pixel coordinates. Lets say you move your object 100pixels in one update (a lot already since you have like one frame time for that distance), multiplied by 0,01f results in object moved one pixel. Now if your screen is 2000px wide, most mobiles are a lot less, even if you drag from one side to the other, you would at most drag it 20pixels \$\endgroup\$ – Zibelas Oct 16 at 8:59
  • \$\begingroup\$ I tried increasing speedModifier but it not working \$\endgroup\$ – Yash Kute Oct 16 at 10:08

Your Answer

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

Browse other questions tagged or ask your own question.