- Home /
C# Xbox One Controller Left Analog Stick Z axis Rotation
So I've been trying to figure this out. I want the attached gameobject to rotate in the direction of the Xbox One left analog stick along the z axis. Except the Xbox One left analog stick doesn't have a z axis so what do I rotate by? I've been modifying some code that was originally intended to follow the mouse cursor's position. I figured if I added Input.GetAxis("L_XAxis_1") and Input.GetAxis("L_YAxis_1") in the z axis of goRotation I might get the z axis. But no response. I'm under the impression that I may have to rotate the gameobject with a different method. What other methods could I use to rotate the gameobject along the z axis?
//Original Code
Vector3 goRotation = Input.mousePosition - Camera.main.WorldToScreenPoint(cam.transform.position);
transform.rotation = Quaternion.LookRotation(Vector3.forward, goRotation);
//Modified Code
Vector3 goRotation = new Vector3 (Input.GetAxis("L_XAxis_1"),Input.GetAxis("L_YAxis_1"),Input.GetAxis("L_XAxis_1") + Input.GetAxis("L_YAxis_1")) - Camera.main.WorldToScreenPoint(cam.transform.position);
transform.rotation = Quaternion.LookRotation(Vector3.forward, goRotation);
Answer by N0T_B4D_H4CK3R5 · Jan 26, 2017 at 04:36 PM
You can use the LookAt function, so your code's going to look like this:
transform.LookAt(goRotation);