- Home /
Question by
vovastarygin · Oct 08, 2017 at 08:47 PM ·
androidunity 5touch controls
Rigidbody doesn't move with touch along x and z axis
Good afternoon, I surfed a lot of code connected with touch on android devices, but none works for me. I'm doing a program with a sphere(Rigidbody ) on a plane which should move by finger on screen. Here's my code for controlling sphere by touches, but it doesn't work ccorrectly along XZ axis.
float speed =1f; void Update() {
if (Input.touchCount > 0 && Input.GetTouch(0).phase == TouchPhase.Moved)
{
Touch x = new Touch();
x = Input.GetTouch(0);
Vector3 touchDeltaPosition = x.deltaPosition;
touchDeltaPosition.y = 0;
touchDeltaPosition.x = touchDeltaPosition.x * speed / 3;
touchDeltaPosition.z = touchDeltaPosition.z * speed / 3;
transform.Translate(touchDeltaPosition * Time.deltaTime);
}
}
Comment
Your answer
Follow this Question
Related Questions
EventSystem.current.IsPointerOverGameObject(t.fingerId) - Not working on Android builds - Unity 2 Answers
Android touch input Null Reference exception error 0 Answers
My rigidbody2d is passing through the side of a collider2d but it's working on the top 0 Answers
Unity can't receive information from Intent *urgent 0 Answers