Search Unity

i need to rotate cube in z axis or x axis one direction at time

Discussion in 'Scripting' started by ahmedarshadcoll, Jan 31, 2020.

?

i need to rotate cube in z axis or x axis one direction at time

  1. solution

    0 vote(s)
    0.0%
  2. does not know

    0 vote(s)
    0.0%
  1. ahmedarshadcoll

    ahmedarshadcoll

    Joined:
    Nov 11, 2019
    Posts:
    7
    i am rotating cube on touch , if i touch and move on left side then it should rotate from left side , and if drag my touch from right side cube should move from right side , cube is placed on (0,45,0 ) rotation , i want that y axis remain same 45 every time , but other axis should be change based on touch direction here is my code


    1. Code (CSharp):
      1.    
      2.  
      3.   if (touchPos.x < Screen.height / 2)
      4.      {
      5.     transform.Rotate(deltaPosition.y * rotSpeed, 0, 0,Space.Self);
      6.      }
      7.      else if (touchPos.x > Screen.height / 2)
      8.      {
      9.     transform.Rotate(0, 0, -deltaPosition.y * rotSpeed,Space.Self);
      10.     }
      11.  
    it works on first side either on left or right , lets suppose i had rotated it from left side first then it changes on z and when z axis become 90 then next time if i will change on right side then it changes y axis and z axis too , if in first time left side will be zero then on right side if works fine , but if z goes to 90 the left side makes issue in rotation alt text upload_2020-1-31_15-50-40.png
    1.PNG
    upload_2020-1-31_15-51-8.png upload_2020-1-31_15-51-59.png
    i want to rotate in only in left side or right side , and center should remain same like below
    upload_2020-1-31_15-53-10.png