Touch based rotation of 3d model
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.
wrongverticlerotationmodel.png
(130.0 kB)
Comment
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 && Game$$anonymous$$anager.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.
screen-shot-2016-02-07-at-33112-pm.png
(62.1 kB)