I want to rotate my 3d model based on horizontal and vertical touch. So I want only x and y rotation applied into model.
But when I just swipe vertically on device then it also get z rotation as well. Here is my screenshot to give you more idea.
Here I have also attached my source code to give you more idea about problem.
void LateUpdate ()
{
// If there are two touches on the device...
if (Input.touchCount == 1 && GameManager.Instance.IsGameStart) {
// Store currnet touch.
Touch touch = Input.GetTouch (0);
transform.RotateAround (transform.position, Vector3.up, -touch.deltaPosition.x Time.deltaTime 15f);
transform.RotateAround (transform.position, Vector3.right, touch.deltaPosition.y Time.deltaTime 15f);
}
}
Please help me to sort out this problem.
instead of Rotate Around use Rotate.
make sure you use Space.Self
I have tried with this kind of code but result remain same.
void LateUpdate ()
{
// If there are two touches on the device...
if (Input.touchCount == 1 && GameManager.Instance.IsGameStart) {
// Store currnet touch.
Touch touch = Input.GetTouch (0);
transform.Rotate (Vector3.up, -touch.deltaPosition.x Time.deltaTime 10f, Space.Self);
transform.Rotate (Vector3.right, touch.deltaPosition.y Time.deltaTime 10f, Space.Self);
}
}
Now I have some sort of improvised code but not able to stop z rotation. Here is my code :
// Update is called once per frame
void LateUpdate ()
{
// If there are two touches on the device...
if (Input.touchCount == 1 && GameManager.Instance.IsGameStart) {
// Store currnet touch.
Touch touch = Input.GetTouch (0);
// transform.RotateAround (transform.position, Vector3.up, -touch.deltaPosition.x Time.deltaTime 15f);
// transform.RotateAround (transform.position, Vector3.right, touch.deltaPosition.y Time.deltaTime 15f);
transform.Rotate (Vector3.up, -touch.deltaPosition.x Time.deltaTime 10f, Space.World);
transform.Rotate (Vector3.right, touch.deltaPosition.y Time.deltaTime 5f, Space.World);
// transform.Rotate (Vector3.forward, 0f, Space.World);
Vector3 objEularAngles = transform.rotation.eulerAngles;
objEularAngles.z = 0f;
transform.eulerAngles = objEularAngles;
}
}
Here is an image that represent what I don’ t want :

In above image, globe is completely rotated in z direction. I don’t want to do this.
Here is one more try from my side, in this I can able to fix z direction rotation but my y direction rotation got stopped.
please give me some hint in this so I can able to solve this problem.
void Update ()
{
// If there are two touches on the device...
if (Input.touchCount == 1 && GameManager.Instance.IsGameStart) {
// Store currnet touch.
Touch touch = Input.GetTouch (0);
// transform.RotateAround (transform.position, Vector3.up, -touch.deltaPosition.x Time.deltaTime 15f);
// transform.RotateAround (transform.position, Vector3.right, touch.deltaPosition.y Time.deltaTime 15f);
// transform.Rotate (Vector3.up, -touch.deltaPosition.x Time.deltaTime 10f, Space.World);
// transform.Rotate (Vector3.right, touch.deltaPosition.y Time.deltaTime 5f, Space.World);
myRigidbody.MoveRotation (myRigidbody.rotation Quaternion.Euler (Vector3.right touch.deltaPosition.y Time.deltaTime 5f));
myRigidbody.MoveRotation (myRigidbody.rotation Quaternion.Euler (Vector3.up -touch.deltaPosition.x Time.deltaTime 10f));
}
}