- Home /
FPS Camera rotates on Z when using a joystick
var rotationX = joy.AxisX * sensX * Time.deltaTime;
var rotationY = joy.AxisY * sensY * Time.deltaTime;
transform.localEulerAngles += new Vector3(rotationX, rotationY, 0);
I'm using a virtual joystick and I've attatched this script to the camera, it works but it rotates on the Z which is so confusing! Even if I add transform.rotation.z = 0; it doesn't make a change! Please help me!
If your transform has a parent you may need to use Transform.eulerAngles otherwise a parent or grandparent could easily by mapping one axis onto another
Can you post please post the code? :) It still doesn't work for me :/ btw the joystick has a input from -1 to 1
$$anonymous$$y suggestion is that your use transform.eulerAngles ins$$anonymous$$d of the LOCAL version, but that will only have any effect if you're transform has a parent.
I cannot tell for sure whether the code you've posted will work, but it looks like it might. Note that euler anglers are prone to gimbal lock, but I couldn't say if you're experiencing this through your use. I might suggest only setting the X or Y angle to begin with and also checking you are using degrees or radians appropriately, though it would seem odd if that was the issue here.
After some more testing I noticed that if I only apply rotation to the Y, it also rotates on Z... It works if I use $$anonymous$$athf.Clamp to make sure it's always 0 but it should not rotate on Z if I only rotate on Y :@ Is this a bug in unity?
Does your transform have any parents?
Did you try .eulerAngles ins$$anonymous$$d of the local version?
Your answer
Follow this Question
Related Questions
Android based ARCore example ObjectManipulation using Joystick Controller 0 Answers
Move towards VR Camera Orientation with Bluetooth Controller (Android) 0 Answers
Gyroscope smooth transitions (minimizing jerk from tiny movements) 1 Answer
2D mobile: Need my character to rotate Z axis towards touch position 0 Answers
Making my Game Object face according to direction of mobile joystick 2 Answers