- Home /
How do I make gameObject.transform.rotation.z equal to a set float value?
I'm trying to make a simple First Person Camera Controlelr for use with the standard Xbox 360 controller.
I couldn't find a way to equal the GameObject's rotation to a particular value without using a Vector3. As it wouldn't allow me to do this:
 if (gameObject.transform.rotation.z > 0f)
 {
    gameObject.transform.rotation.z == 0f;
 }
Attempting to use a new Vector3 to hold my desired values has also been futile:
 if (gameObject.transform.rotation.z > 0f) //Z-axis rotation limit.
         {
             gameObject.transform.rotation.z = new Vector3(fControllerZLimit,fControllerZLimit,fControllerZLimit);
         }
gameObject.transform.Rotate won't work for this as I need the Camera's Z axis to always equal 0 so it stays upright.
Rotation is a pain T-T
Answer by aditya · May 17, 2016 at 05:23 AM
         Vector3 tempRot = new Vector3 ();
         tempRot.z = fControllerZLimit;
         gameObject.transform.rotation = Quaternion.Euler (tempRot);
initialize tempRot with values that you don't want to be changed ever 
Answer by arbazgillani · May 17, 2016 at 05:46 AM
Use Gameobject.Qauternion.euler(x,y,z); save the values of x,y as required and put the z value which you want. Your problem will be solved.
Your answer
 
 
              koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                