Rotate child z axis

Updated on October 17, 2017 in  [R] Scripts
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on October 17, 2017

I have player( parent) and a camera (child) and I wan’t to make a on Q button to make player sneak. X axis moves great, but it doesn’t rotates (need like -20degress rotation in Z).Code as follows:

 

 void Start()
 {
   player = GetComponent();
   mainCamera = GetComponentInChildren();
   standingX = mainCamera.transform.localPosition.x;
   standingY = mainCamera.transform.localPosition.y;
   standingZ = mainCamera.transform.localPosition.z;
   rotatingZ = mainCamera.transform.localEulerAngles.z;
   crouchHeight = (standingY - (standingY / 2));
   sneakRightHeight = (standingX - 0.700f);
   sneakLeftHeight = (standingX + 0.700f);
   sneakRightRotation = (rotatingZ + 20.000f);
   sneakLeftRotation = (rotatingZ - 20.000f);
 }

 

//in FixedVoid()
 //sneakLeft
 if (Input.GetButton("Q") && sneakingLeft == false)
 {
   sneakingLeft = true;
   Debug.Log(standingX.ToString());
   mainCamera.transform.localPosition -= new Vector3(sneakLeftHeight, 0, 0);
   if (sneakingLeft == true && sneakLeftXMoved == false)
   {
       //rotation
       sneakLeftXMoved = true;
       //mainCamera.transform.localEulerAngles -= new Vector3(0, 0, sneakLeftRotation);
   }
 }
 else if (!Input.GetButton("Q") && sneakingLeft == true)
 {
   sneakingLeft = false;
   mainCamera.transform.localPosition += new Vector3(sneakLeftHeight, 0, 0);
   if (sneakingLeft == false && sneakLeftXMoved == true)
   {
      //rotation
      sneakLeftXMoved = false;
      //mainCamera.transform.localEulerAngles += new Vector3(0, 0, sneakLeftRotation);
   }
 }
  • Liked by
Reply