Search Unity

Touch based rotation goes wrong after some rotation applied to model

Discussion in 'Scripting' started by siddharth3322, Feb 12, 2016.

  1. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    Basically I want to rotate my 3d model using horizontal and vertical touches. For this I have written something like this type of code. But I want to restrict z rotation of 3d model so applied different code for it.

    Code (CSharp):
    1. Vector2 touchPosition = touch.deltaPosition;
    2.     currentAngle.y += rotationSpeed.x  touchPosition.x  Time.deltaTime;
    3.     currentAngle.x += rotationSpeed.y  touchPosition.y  Time.deltaTime;
    4.     currentAngle.z += rotationSpeed.z * Time.deltaTime;
    5.     transform.eulerAngles = currentAngle;
    After applying this code, if I rotate my model 180 degree in y rotation then horizontal and vertical swipe control start working in reverse direction. If I swipe left side then model rotated over right side.

    If model is rotated around 90 degree in y rotation then behaviour got changed in half way. I hope now you understand what I am trying to say.

    I want functionality like, if I swipe in left direction then model gets rotated in left direction, if I swipe in right direction then model gets rotated in right direction whatever the current rotation of model. But want to restrict z rotation that is for most condition but that I have already restricted in above code.